How can I get avatar for authors who haven't post any content yet.
I have created a specific page for each author which shows the author s posts like a blog.
But for those with no post, WordPress display a default avatar instead of user s chosen profile picture.
here is my code for author`s info:
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
<div class="nauthor-brief" style="">
<?php echo get_avatar( get_the_author_meta( 'ID' ) , 60 ); ?>
<div class="nauthor-brief-text">
<h2> <?php echo $curauth->display_name; ?></h2>
<p id="nauthor-description"><?php echo $curauth->user_description; ?></p>
</div>
</div>
Step 1: Log into your WordPress Dashboard
Step 2: In the left menu, under "Appearance", click "Editor"
Step 3: On the "Editor" page, find and click "content.php" in the list of files on the right of the page
Step 4: Find this section of code:
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
... and replace it with this:
<div class="entry-meta">
<? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?>
That's it, you're done! In this tutorial we placed the author's avatar at the top of the post (for the homepage). If you'd like show the author's avatar from anywhere else within the post (or on other pages), simply use the following code:
<? echo get_avatar( get_the_author_meta('user_email'), $size = '50'); ?>
Related
I'm building my own template for Wordpress and I'm bumping into an issue when displaying the content of a post.
I have already built one page template for the home page and it works fine. The loop outputs what I want to display. Now I'm building the template to display an article but the loop doesn't return anything.
Here is the code of the page template:
<?php
/*
Template Name: PAGE
*/
define( 'WP_USE_THEMES', false );
get_header();
?>
<div class="wrapper">
<div class="sidebar">
<?PHP get_sidebar(); ?>
</div>
<div class="main">
<div class="section group">
<div class="col col12-12">
<span>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</span>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
This results in displaying the "sorry, no posts matched your criteria" message when i click on one of the links on the homepage. The strange thing is that the page really exists (it has ID=26 as you'll see here below):
<?php
$post = get_post(26);
$title = $post->post_title;
echo $title;
?>
This works and displays the expected title. I have tried get_the_ID(); to get the post ID but it returns an empty variable.
There is probably something missing in my template but I can't figure out what.
Any idea?
Thanks
I have found the issue and it had nothing to do with the template itself.
I discovered what's wrong by using one of the standard Wordpress themes (twentyfifteen) where every post led me to a 404 even if I clicked on a post from the Admin UI. I swapped back permalink structure to the ?p=123 option and there everything working. Definitely a permalink structure problem.
The problem was coming from the polylang plug-in. I'm using a network of wordpress site for which I have made this plug-in available. I did not need this plug-in for this particular site but somehow it needed to be active anyway. So I activated polylang and configured it to have only one language and now it works.
Got new gray hair in the process but if that can help anyone...
Thanks for your help!
Laurent
I don't think, that this template can output any posts like this. For WordPress
/*
Template Name: PAGE
*/
indicates: this is a page-template which you can asign to the content of a page but not to a post.
When you want to show a specific post on such a page you will have to:
Asign the template to the page in WP-backend
Add a new query to the template to show the post
Like:
<?php
/*
Template Name: PAGE
*/
define( 'WP_USE_THEMES', false );
get_header();
?>
// The new Query
$args = array (
'p' => '26',
);
// The Query
$query = new WP_Query( $args );
<div class="wrapper">
<div class="sidebar">
<?PHP get_sidebar(); ?>
</div>
<div class="main">
<div class="section group">
<div class="col col12-12">
<span>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</span>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
But as this is very complicated I would recommend to:
delete the /* Template Name: PAGE */ from the template
save it as single.php or more specific as single-26.php
link to the desired post in your wp-menu
I installed a plugin called Admin Guide Dashboard Widget. The idea is that it adds a widget to the WordPress Control Panel (the first screen that shows up upon login). On this widget you choose a blog/post category and then every post you write with that category shows up in that widget.
Well it didn't work at all. The widget showed all of my posts. I tried to change the category on the widget, but I just couldn't get it to work so I uninstalled it. Then I realized the the_content() of all my blog posts was gone. I tried to install the plugin again, I tried to change the category I had set for the plugin, nothing worked. I uninstalled. The content part of my posts is still not showing up at all.
Before I installed that plugin I had only created one category, called "Nyheder"
Now I'm not sure if all of my posts were categorized as "Nyheder" or if they were simply uncategorized. I tried unchecking "Nyheder" from my posts but it gets checked again automatically. I don't know if my posts should be uncategorized (if that's even possible) or if the problem lies somewhere else.
The news archive page of the website in question is here. This page actually still shows the content. But if you click on a posts's title to go to its page, you will see that there is no content.
Here is the code on my single.php page, but I really doubt this is the problem.
<?php get_header(); ?>
<div id="pageHead">
</div>
<div id="main2" class="page clearfix">
<div id="content" class="threeFourth clearfix" style="width:100%;"><?php get_sidebar(); ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<h1 style="display:inline;"><?php the_title(); ?></h1>
<?php
$page = $_SERVER['REQUEST_URI'];
if (substr($page, 1, 14) == "events_listing") {
echo "<h2>" . do_shortcode('[events-listing-date]');
if(do_shortcode('[events-listing-end-date]') != get_the_modified_date('d-m-Y') ) {
echo " til " . do_shortcode('[events-listing-end-date]') . "</h2>";
}
}
?>
<br>
<div class="meta clearfix" style="display:inline-block; padding-top: 10px; font-size: 14px;">
<?php _e('Skrevet af', 'themetrust'); ?> <?php the_author_posts_link(); ?> <?php _e('d.', 'themetrust'); ?> <?php the_time( 'j. F, Y' ) ?><br><br>
</div>
<?php edit_post_link(__('Edit Post', 'themetrust'), '<p>', '</p>'); ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div>
</div>
It looks like it had nothing to do with the plugin, but instead with another change I had made just before installing it. If you look at the code above, I defined a variable called $page. It turns out if I inserted the_content() before that it worked fine, but not after! So I changed the name of the variable to something else and put the_content() back in its place. Voila! I guess there was a conflict with the variable name $page and it somehow affected the_content().
I am trying to tweak NextGen Gallery plugin, and in particular the file nextgen-gallery/view/gallery.php to achieve displaying the gallery description, when I view the gallery.
So, in this file, I have added the following lines:
....
<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
<?php if (!empty ($gallery)) : ?>
<?php /** Lots of stuff added here by Mpampirina **/ ?>
<p> You are here: <a class="Link" href="<?php echo get_permalink(); ?>">
<?php the_title(); ?></a> >
<?php $album = nggdb::find_album( get_query_var('album') ); ?>
<?php echo $album->name ?> > <?php echo $gallery->title ?>
</p>
<div class="ngg-description">
<p>Here I want to add the gallery description text. So I try with:
<?php echo $gallery->gallerydesc ?> . Also I try with:
<?php echo $gallery->galdesc ?> .
I get no description, whatsoever...
</p>
</div>
<?php /** End of stuff added by Mpampirina **/ ?>
<div class="ngg-galleryoverview" id="<?php echo $gallery->anchor ?>">
...
And here is the output:
The gallery description of course is not empty. There is text added, in the 'Manage Gallery" menu:
So, is there anybody who can see what I am doing wrong, or maybe point me to another question page that I might have missed? It would be very helpful! :-)
Thank you in advance
I just dealt with the same problem...
$gallery->description
When I installed WordPress I had a home menu. While editing, I added a menu item to the menu but my home menu item disappeared.
I don't know what's going on. How do I add the home menu item which links to homepage back?
I'm not sure why your home item would have disappeared after adding another item, but make sure your theme is using wp_page_menu():
http://codex.wordpress.org/Template_Tags/wp_page_menu
This carries the benefit of listing your "Home" along with your other pages.
Edit the line in the header.php
wp_page_menu( 'show_home=1');
reference in the codex : http://codex.wordpress.org/Function_Reference/wp_page_menu
If you have already added Home as menu, then copy the content of index.php into your Home.php (create this empty file in your theme) file.
Then run and check the home page.
Step 1. For linking your home page, create index.php as template file for home like the code below:
Use these codes if you're using custom theme(theme created by yourself in themes folder of wp-content other than twentyelevan, twentyten and so on.
<?php
/**
* Template Name: home
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
// whatever body code u need,u can include it here.
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-header">
<!-- <div class="date"><?php the_time( 'M j y' ); ?></div>-->
<!-- <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent
Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>-->
<!-- <div class="author"><?php the_author(); ?></div>-->
</div><!--end post header-->
<div class="entry clear">
<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<!-- <?php edit_post_link(); ?>-->
<?php wp_link_pages(); ?>
</div><!--end entry-->
<div class="post-footer">
<!-- <div class="comments"><?php comments_popup_link( 'Leave a Comment', '1
Comment', '% Comments' ); ?></div>-->
</div><!--end post footer-->
</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<div class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</div><!--end navigation-->
<?php else : ?>
<?php endif; ?>
<div id="slider">
<?php
$tmp = $wp_query;
$wp_query = new WP_Query('posts_per_page=5&category_name=featured');
if(have_posts()) :
while(have_posts()) :
the_post();
?>
<a href="<?php the_permalink(); ?>"><?php
the_post_thumbnail('nivothumb'); ?></a>
<?php
endwhile;
endif;
$wp_query = $tmp;
?>
</div><!-- close #slider -->
<?php get_footer(); ?>
Or, if you're using wordpress builtin themes, then use these codes:
<?php
/**
* Template Name: onebyone
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<html>
// whatever body code u need,u can include it here.
</html>
Step 2. Then open the home page in wordpress, Pages -> All pages, click edit.
Step 3. In edit page of home, in the right side you will see Dropdown named Template. Click the
dropdown, there you will see your template name as home select it and then click update
button.
Step 4. Then,On top left side corner,click your website or blog name and visit the website or
blog to check your home page by clicking on it.
Do you have a link to your site?
It may be as simple as checking a box. OR, you can create a custom menu.
You can see here what i am doing:
http://www.arvag.net/otkrijte-svet/leto/
So its pulling 2 custom fields from child pages, one of them is just url for the image on the left, and the other field is that text showing on the right.
Now, what i want to do is to add pagination there. The code i have now will just simply show all child pages, but i want to show only 5 child pages, so if user want to see 6th child page he would have to click on link for "Page 2" and so on.
The code im using to display these child pages is this:
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=post_title&sort_order=desc');
$count = 0;
foreach($pages as $page)
{
$short_info = get_post_meta($page->ID,'info',true);
$image = get_post_meta($page->ID,'slika',true);
$count++;
?>
<div class='preview_slika left'><img src="<?php echo $image ?>" alt="<?php echo $page->post_title ?>" /></div>
<div class='preview_info right'>
<h2><?php echo $page->post_title ?></h2>
<p><?php echo $short_info ?></p>
Više o >>
</div>
<div class='clear'></div>
<?php
}
?>
So any idea what to do to get what i need?
Take a look at wp-PageNavi plugin. And this blog post if you want to integrate it in your theme an not have another plugin to manage.
Some guy posted some sample code on wordpress forums which works much better for me than this plugin.
http://wordpress.org/support/topic/383773