WordPress.org

Ready to get started?Download WordPress

Forums

Inserting Recent Posts into Footer (2 posts)

  1. pickledegg
    Member
    Posted 6 years ago #

    I'm trying to display the 5 most recent posts of all categories in the footer. I used an existing theme and this is what is currently in the footer:

    <div class="left">
    			<h2>Previous entries</h2>
    			<ul class="block">
    <?php
    $myposts = get_posts('numberposts=4&offset=1');
    if ($myposts) :
    	foreach ($myposts as $post) :
    		setup_postdata($post);
    				unset($categories);
    		foreach (get_the_category() as $category)
    			$categories[] = $category->cat_name;
    ?>
    				<li><a href="<?php the_permalink();?>"><span><?php the_title(); ?></span><em><?php the_date();?> in <?=implode(", ",$categories);?></em></a></li>
    <?php endforeach;?>
    <?php else : ?>
    				<li>no entries</li>
    <?php endif;?
    			</ul>
    </div>

    But its alway showing 'no entries'.

    I know the recent posts sidebar widget works, and if better suited, how do I go about putting that into the footer?

    Many thanks.

  2. Kalessin
    Member
    Posted 6 years ago #

    I copied and pasted your code into my site's sidebar and it worked fine... after I changed the line
    <?php endif;?
    to read
    <?php endif;?>

    Are you sure you actually have some posts? This code will not pick up Pages.

Topic Closed

This topic has been closed to new replies.

About this Topic