[Wordpress]How to display recent posts in a page?

avatar33

e-Hustler
Dec 5, 2009
3,838
52
48
Calgary, AB
Say I'm building this page on my Wordpress site with lots of content, then at the bottom of it I want to add a table and have my 10 latest posts listed there. How do I do that?

I've always been displaying my recent posts in the sidebar so it was easy (just basically using the widget), but now I want to display them within this one page and I'm clueless on how to do it.

Thanks!
 


This is in a <ul> structure, but not too hard to convert to a <table>:

Code:
<ul>
  <li>
    <h2>Posts Recentes</h2>
    <ul>
    <?php
      $number_recents_posts = 5;//Can be how much you want
      $recent_posts = wp_get_recent_posts( $number_recents_posts );
      foreach($recent_posts as $post){
        echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
      } ?>
    </ul>
  </li>
</ul>

(Source) Check this out for more info:
Function Reference/wp get recent posts « WordPress Codex
 
Use my plugin: WordPress › Custom Shortcode Sidebars « WordPress Plugins

Lets you create sidebars within your content using shortcodes (aka: widgets in post). Let me know if you need help with it. I didn't put a lot of documentation with it :-/

Would you mind posting a screenshot of what this ends up looking like? Is it literally like being able to put a widget in post? Such a simple idea, I wonder why no ones done this before.
 
jgrim, I can't figure out your plugin... I installed it, activated it, went to "custom sidebars" under settings and created a new sidebar, then I went to widgets and added the "Recent Posts" widget to this new sidebar. Then I added the shortcode inside my homepage where I wanted the posts to appear, but they don't. Did I miss something?
 
  • Like
Reactions: jgrim
Would you mind posting a screenshot of what this ends up looking like? Is it literally like being able to put a widget in post? Such a simple idea, I wonder why no ones done this before.

attachment.php


After you activate the plugin a menu appears under Settings -> Custom Sidebars. The settings are as shown above. You fill in the fields as necessary. Make note of the shortcode that you will later need to add to your post.

Next, you go to the Appearance -> Widgets Page and added widgets to the new sidebar added on the side.

After you add the shortcode to your page or post you should see a sidebar created within your post.

jgrim, I can't figure out your plugin... I installed it, activated it, went to "custom sidebars" under settings and created a new sidebar, then I went to widgets and added the "Recent Posts" widget to this new sidebar. Then I added the shortcode inside my homepage where I wanted the posts to appear, but they don't. Did I miss something?

I'm not sure what's going on, give me a link to your blog so I may check it out. I've never had an error reported in this version, maybe my shit is weak.
 

Attachments

  • Region-capture-1.jpg
    Region-capture-1.jpg
    36.3 KB · Views: 20
There was a bug in the plugin. I fixed it and updated the Wordpress plugin repository. The new version will be v1.2, it takes up to 15 minutes for updates to post if anyone is looking to use it.

Thanks Avatar33 for helping me discover a bug. +rep
 
  • Like
Reactions: avatar33