Tagged: x
-
AuthorPosts
-
March 22, 2017 at 11:28 pm #1417202
Hello,
I’m having trouble moving ‘x_renew_entry_meta’ to the landmark_header. I’ve successfully created a large background featured image for single posts in the header, and I’d like the title to float over it (as shown in the screen grab). I placed the ‘x_renew_entry_meta’ underneath the title, but I can’t get the post author to show. Everything else (date/categories/comment count) shows, but the post author doesn’t.
Here’s what I have now in the functions.php:
if ( ! function_exists( ‘x_renew_entry_meta’ ) ) :
function x_icon_entry_meta() {$author = sprintf(‘<span class=”show-date”>%2$s</span>’,
get_author_posts_url( get_the_author_meta( ‘ID’ ) ),
get_the_author()
);$date = sprintf( ‘<span><time class=”entry-date” datetime=”%1$s”>%2$s</time></span>’,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date( ‘m.d.Y’ ) )
);$post_type = get_post_type();
$post_type_post = $post_type == ‘post’;
$post_type_portfolio = $post_type == ‘x-portfolio’;
$no_post_meta = x_get_option( ‘x_blog_enable_post_meta’ ) == 0;
$no_portfolio_meta = x_get_option( ‘x_portfolio_enable_post_meta’ ) == 0;if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) {
return;
} else {
printf( ‘<p class=”p-meta”>%s|%s</p>’,
$author,
$date
);
}}
endif;Thanks!
March 23, 2017 at 3:06 am #1417331Hello There,
Thanks for writing in! The code should have been this:
if ( ! function_exists( 'x_renew_entry_meta' ) ) : function x_renew_entry_meta() { $author = sprintf('<span class="show-date">%2$s</span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author() ); $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>', esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date( 'm.d.Y' ) ) ); $post_type = get_post_type(); $post_type_post = $post_type == 'post'; $post_type_portfolio = $post_type == 'x-portfolio'; $no_post_meta = x_get_option( 'x_blog_enable_post_meta' ) == 0; $no_portfolio_meta = x_get_option( 'x_portfolio_enable_post_meta' ) == 0; if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) { return; } else { printf( '<p class="p-meta">%s|%s</p>', $author, $date ); } } endif;
If this doesn’t work, would you mind providing us the url of your site with login credentials so we can take a closer look and fix the issue? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password
– FTP Hostname
– FTP Username
– FTP PasswordDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thank you.
March 23, 2017 at 10:09 am #1417756This reply has been marked as private.March 23, 2017 at 6:44 pm #1418343Hi there,
Please try this one
if ( ! function_exists( 'x_renew_entry_meta' ) ) : function x_renew_entry_meta() { $author = sprintf('<span class="show-author"><a href="%1$s">%2$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author() ); $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>', esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date( 'm.d.Y' ) ) ); $post_type = get_post_type(); $post_type_post = $post_type == 'post'; $post_type_portfolio = $post_type == 'x-portfolio'; $no_post_meta = x_get_option( 'x_blog_enable_post_meta' ) == 0; $no_portfolio_meta = x_get_option( 'x_portfolio_enable_post_meta' ) == 0; if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) { return; } else { printf( '<p class="p-meta">%1$s|%2$s</p>', $author, $date ); } } endif;
Hope this helps.
March 23, 2017 at 7:15 pm #1418364Thanks. This doesn’t work, either. I’ve tried similar calls multiple times. It seems to have something to do with it being outside the actual entry.
Is there a way to call the entry within this function so that
'get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author()
retrieves the author successfully? I’m able to pull the author’s URL, but the name doesn’t show up.
Thanks,
NateMarch 24, 2017 at 2:33 am #1418729Hi Nate,
Can you provide us your ftp login so we can properly edit the code.
Thanks
March 24, 2017 at 8:54 am #1418992I can’t provide an FTP login, but if you tell me which files to edit I can do it. Possible? Is there a way to call the current single post from the landmark_header?
I know this is outside the scope of support, so I really appreciate the assistance!!
Thanks
March 24, 2017 at 6:19 pm #1419622Hi there,
Unfortunately, I’m not sure why it’s not working on your end either so can’t tell which files needs fixing, it’s best to check it directly. Post meta code are within the entry post since it’s within post loop or global post.
Thanks!
March 24, 2017 at 6:47 pm #1419642Everything else – date, category, comments – are working. Does anything come to mind that could cause `get_author
specifically not to work?
Thanks!
March 25, 2017 at 4:47 am #1419959Hello There,
Thanks for updating in! After several tries, it turns out that you will need this code:
$author = sprintf( '<span>by %1$s %2$s</span>', esc_attr( get_the_author_meta( 'first_name', get_current_user_id() ) ), esc_attr( get_the_author_meta( 'last_name', get_current_user_id() ) ) );
If you need anything else, please let us know.
March 25, 2017 at 11:10 am #1420124Awesome. Thanks! I should be able to tweak this to make the name link, etc.
Thank you so much!!
March 25, 2017 at 11:54 am #1420150You’re most welcome 🙂
March 25, 2017 at 12:26 pm #1420161One more question: I’m also trying to call the author avatar in this string, but I’m coming up with the generic avatar. Same issue I suppose. Here’s what I tried:
$avatar = sprintf( '<span>by <a href="%1$s">%2$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_avatar( get_the_author_meta( 'ID' ), 32 ) );
The generic avatar is being added, so I know this is again an issue with calling the specific post author. I’ve been digging through the theme files trying to find the attributes, but I’m not having any luck. Could you you show me how to fix the above?
March 25, 2017 at 4:30 pm #1420268I figured it out! This is what worked for me, in case anyone else is curious:
$avatar = sprintf( '<span>by <a href="%1$s">%2$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID', get_current_user_id() ) ), get_avatar( get_the_author_meta('user_email', get_current_user_id() ), 32 ) );
March 26, 2017 at 12:48 am #1420453Hello Again,
We are just glad that you have figured it out a way to correct the said issue.
Thanks for letting us know!Best Regards.
-
AuthorPosts