Latest Post by Author code
-
I am using the Carolina theme on a multi-author WP blog. I want to display 1-2 most recent post for each author at the bottom of the template. I cannot figure out where to put this code in the theme.
<?php echo do_shortcode(‘[latestbyauthor author=”username” show=”3″]’); ?>
Thanks.
pamhttps://www.ads-software.com/plugins/latest-posts-by-author/
-
If you want it to be displayed on every page of the site, you’ll probably want to put it in the footer.php file.
OK. I put this:
<?php echo do_shortcode(‘[latestbyauthor author=”cpmaz, p2h, mbryanaz” show=”3″]’); ?>in the footer, thinking it would display the 3 most recent posts for these 3 authors in the code.
In the #4 slot of the footer, 3 posts from 3 different authors– not the people listed in the above code– displayed. Earlier I had tried putting [latestbyauthor] as a tag on three posts. That is what came up on the list on the page.
I thought with the widget that it would identify the author and give the latest posts. Is this not the case?
I’m getting closer. Thanks for your help.
pam
I’m not sure if I understand exactly what you did. The code you used should display only 3 posts, not three posts for each author. I’m not sure if that was a source of confusion or not. Also, I’m not sure what you meant when you said that you “thought with the widget that it would identify the author and give the latest posts.” Latest Posts by Author doesn’t come with a widget. It simply displays a list of posts wherever the shortcode is used. I’m not sure if any of this info is helpful or not. Feel free to follow up with any other details/questions you have, and feel free to post a link to the site you’re working on if it’s live. Thanks!
I am looking for a plug-in that will display the author’s name and that author’s most recent post– or display each author’s name and the most recent post from each author.
I misspoke when I said “widget”. I really appreciate your help.
pam
You should be able to do that manually with this plugin if you’d like. It would look something like this:
<h3>cpmaz</h3> <?php echo do_shortcode('[latestbyauthor author="cpmaz" show="1"]'); ?> <h3>p2h</h3> <?php echo do_shortcode('[latestbyauthor author="p2h" show="1"]'); ?> <h3>mbryanaz</h3> <?php echo do_shortcode('[latestbyauthor author="mbryanaz" show="3"]'); ?>
Is that what you were trying to do?
I pasted that in the footer and the code shows.
We’re getting close.
Here is the development site.
https://blogforarizona.net/Thank you so much.
pam
That’s pretty strange. Can you paste the contents of your footer.php file here so I can take a look? It doesn’t have to be the whole file, but at least 5 lines before and after the code I gave you so I can see the context and hopefully figure out why it’s doing that? Thanks!
Here are the guts of the footer code. Thanks!!!!
</div><!– #content-box –>
<div id=”footer” role=”contentinfo”>
<?php get_sidebar( ‘footer’ ); ?><h3>cpmaz</h3>
<?php echo do_shortcode('[latestbyauthor author="cpmaz" show="1"]'); ?><h3>p2h</h3>
<?php echo do_shortcode('[latestbyauthor author="p2h" show="1"]'); ?><h3>mbryanaz</h3>
<?php echo do_shortcode('[latestbyauthor author="mbryanaz" show="3"]'); ?><div id=”colophon”>
<?php printf( __( ‘Theme: %1$s by %2$s’, ‘coraline’ ), ‘Coraline’, ‘Automattic.’ ); ?> <span class=”generator-link”>” title=”<?php esc_attr_e( ‘A Semantic Personal Publishing Platform’, ‘coraline’ ); ?>” rel=”generator”><?php printf( __( ‘Proudly powered by %s.’, ‘coraline’ ), ‘WordPress’ ); ?></span>
</div><!– #colophon –>
</div><!– #footer –>There are 3-4 footer slots available in the footer. (Currently, I have Twitter feeds roughed out for 3 of them and links to author bios in #1.)
Ideally, I’d like to have at least 3 of those footer areas with author names and the most recent post. (We have like 9 authors on this blog, so I don’t want a big long strip in just one footer section.)
Thanks so much.
pam
It sounds like what you’d like to do is use the shortcode inside a text widget so that it will fit in the footer widget area. If you follow the instructions in this article, you’ll be able to use the “latestbyauthor” shortcode inside a text widget: https://digwp.com/2010/03/shortcodes-in-widgets/
Thanks. It looks as if the code didn’t work yesterday because it got corrupted when I pasted it. I cleaned up the odd characters, and now works.
I’ll check out the link about using the code with a widget.
I also thought that I could create a table and put each author in a cell of the table in the footer.
pam
I’m glad to hear you got it figured out!
OK, that all worked but then the admin said that he wanted the recent author posts in the top featured widget instead of in the bottom html code.
One of the articles that you sent me said to put the short code in the function php.
I had no idea WHERE to add the code, so I added this code (recommended by one of the articles that you suggested) to the Area 3 featured widget.
add_filter( ‘widget_text’, ‘shortcode_unautop’);
add_filter( ‘widget_text’, ‘do_shortcode’);I got this error.
Parse error: syntax error, unexpected ‘;’, expecting ‘)’ in /home/content/90/12199590/html/wp-content/themes/coraline/functions.php on line 263I deleted the two lines of code and I still get the same error!!! I didn’t copy the original code. (Yes, KICKING MYSELF.)
The area where I added the code looks like this now. (I added and deleted the short code after the “description” section.)
// Area 3, located above the primary and secondary sidebars in Content-Sidebar-Sidebar and Sidebar-Sidebar-Content layouts. Empty by default.
register_sidebar( array(
‘name’ => __( ‘Feature Widget Area’, ‘coraline’ ),
‘id’ => ‘feature-widget-area’,
‘description’ => __( ‘The feature widget above the sidebars in Content-Sidebar-Sidebar and Sidebar-Sidebar- Content layouts’, ‘coraline’ ),
‘before_widget’ => ‘<li id=”%1$s” class=”widget-container %2$s”>’,
‘after_widget’ => ”,
‘before_title’ => ‘<h3 class=”widget-title”>’,
‘after_title’ => ‘</h3>’,
) );ACK! Please help.
pam
I don’t see an error in the code you posted there, but I could be missing something. Why don’t you send me an email using the contact form on my website. I’ll respond and then you can attach the entire functions.php file to an email and I’ll take a look. Here’s a link to my contact form: https://sackclothstudios.com/contact
Thanks so much. I sent it.
- The topic ‘Latest Post by Author code’ is closed to new replies.