warpdesign
Member
Posted 1 year ago #
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.
warpdesign
Member
Posted 1 year ago #
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> ';
}
?>
warpdesign
Member
Posted 1 year ago #
Thanks. That seems to change what one post it returns but it still only returns one post and not from the correct category... :\
warpdesign
Member
Posted 1 year ago #
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..)