Support » How-To and Troubleshooting » Display ‘Recent Posts’ Outside of the Sidebar

Display ‘Recent Posts’ Outside of the Sidebar

  • Hello,

    I think this is probably quite simple but I’m not sure where to get the code. I want to display the ‘recent posts’ widget on my main index page – however it’s going to be displayed somewhere in the content area and not in the sidebar.

    Know where I can find the code that I’d need to do this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • You can widgetize your content area as explained in this thread either with code, or by this plugin.

    Or, you could use multiple loops to do the same thing.

    Awesome. Thanks!

    Quick question about the Widgets on Pages plugin:

    I want to add the widget inside of my main index.php file – however it’s not within editable code. It’s being setup as:

    <div id="featured">[widgets_on_pages]</div>

    However it doesn’t interpret the widgets_on_pages code correctly. Is there any other way to add this to my index.php page?


    I do not use the plugin, so I am guessing here. According to the plugin page, it needs an id number or name unless you are using the default sidebar:

    <div id="featured">[widgets_on_pages id=x]</div>

    Without the id, I think you will get whatever widgets are set up in the main sidebar of the theme.

    @vtxyzzy : I tried that as well. However putting that code inside of index.php renders [widgets_on_pages id=x] as regular text instead of interpreting it as code.

    Please post a few lines of code around the shortcode – about 10 before through 10 after. Be sure to enclose the code in backticks.

    @vtxyzzy : Are you asking for a sample of my code from the index.php page?

    Sorry, I misread what you are doing. The shortcode should go on the page or post, not in index.php.

    @vtxyzzy I want to be able to put recent posts in my index.php (outside of the sidebar) – how else can I do that without the plugin?

    Use multiple loops as I mentioned earlier. Use code similar to this before or after the main loop of index.php:

    $args = array(
       'posts_per_page' => 5, // The number of recent posts to show
       'caller_get_posts' => 1,  // Don't show sticky posts first
    $my_recent = new WP_Query($args);
    if ($my_recent->have_posts()) :
       while ($my_recent->have_posts()) :
          setup_postdata($post); ?>
          <!-- insert code here to display the post -->
       <?php endwhile; ?>
    <?php endif;
    wp_reset_query(); ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display ‘Recent Posts’ Outside of the Sidebar’ is closed to new replies.