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

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘Inserting Recent Posts into Footer’ is closed to new replies.