WordPress.org

Ready to get started?Download WordPress

Forums

Display 'Recent Posts' Outside of the Sidebar (11 posts)

  1. foochuck
    Member
    Posted 4 years ago #

    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?

  2. vtxyzzy
    Member
    Posted 4 years ago #

    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.

  3. foochuck
    Member
    Posted 4 years ago #

    Awesome. Thanks!

  4. foochuck
    Member
    Posted 4 years ago #

    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?

    Thanks

  5. vtxyzzy
    Member
    Posted 4 years ago #

    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.

  6. foochuck
    Member
    Posted 4 years ago #

    @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.

  7. vtxyzzy
    Member
    Posted 4 years ago #

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

  8. foochuck
    Member
    Posted 4 years ago #

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

  9. vtxyzzy
    Member
    Posted 4 years ago #

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

  10. foochuck
    Member
    Posted 4 years ago #

    @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?

  11. vtxyzzy
    Member
    Posted 4 years ago #

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

    <?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()) :
          $my_recent->the_post();
          setup_postdata($post); ?>
          <!-- insert code here to display the post -->
       <?php endwhile; ?>
    <?php endif;
    wp_reset_query(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic