• I want to display recent posts for the current category. This is what I have but it doesn’t’ work:

    <?php
    $args = array( ‘numberposts’ => ‘5’, ‘category’ => ‘8’ );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $post ){
    echo ‘

    • ‘ . $post[“post_title”].’
    • ‘;
      }
      ?>

      What I get when I do that is it only displays 1 post and it isn’t from category 8 but appears to just be the single most recent post regardless of category.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter warpdesign

    (@warpdesign)

    Sorry here it is again

    <?php
    	$args = array( 'numberposts' => '5', 'category' => '8' );
    	$recent_posts = wp_get_recent_posts($args);
    	foreach( $recent_posts as $post ){
    		echo '<li><a href="' . get_permalink($post["ID"]) . '" title="'.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
    	}
    ?>
    Alwyn Botha

    (@123milliseconds)

    Try adding wp_reset_query if you use this in a sidebar

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Thread Starter warpdesign

    (@warpdesign)

    Thanks. That seems to change what one post it returns but it still only returns one post and not from the correct category… :\

    Thread Starter warpdesign

    (@warpdesign)

    So, playing around with the code I’ve tried this

    <?php
    wp_reset_query();
    $recent_posts = wp_get_recent_posts('numberposts=5&category=8');
    	foreach( $recent_posts as $post ){
    		echo '<li><a href="' . get_permalink($post["ID"]) . '" title="'.$post["post_title"].'" >' .   $post["post_title"].'</a> </li> ';
    	}
    ?>

    What that gets me now is 17 posts returned from apparently every category. Very strange. The default showposts is 10 so why I get 17 when I specify 5 I have no idea.

    (by the way the layout of this page is really jacked up in google chrome..)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Display recent posts for category’ is closed to new replies.