wp_get_recent_posts
-
Hi there, i’m making my own theme and i have a little problem with one function.
I just want to show the last 5 post (publish post), without taking in count the category. So when the visitor goes to a category at the sidebar could see the last X (could be 5 or 10) last post published.
To make that i’m using the function wp_get_recent_posts but there is a problem apparently because doesnt work. It crash when try to load the file sidebar.php with that function. And i know that the problem is wp_get_recent_posts because if i use a loop with query_post works fine (but i dont want to use this function!).
I paste here the code, its almost the same that it s in the Codex page.
<ul id="LastPostList"> <?php $args = array( 'numberposts' => 5, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); $recent_posts = wp_get_recent_posts( $args, $output = ARRAY_A ); foreach ($recent_posts as $recent) { ?> <li class="LastPost"><a href="<?php get_permalink({$recent['ID']}) ?>" title="<?php esc_attr({$recent['post_title']})?>" ><?=$recent["post_title"]?></a></li> <?php } ?> </ul>Maybe there is something that i cant see… i also try to enable the debug option but didnt shows anything, and the server error file nether.
-
Have you looked at WP Query? http://codex.ww.wp.xz.cn/Class_Reference/WP_Query
caused by the curly brackets you have in your code which are not in the Codex examples;
change the one line to:
<li class="LastPost"><a href="<?php get_permalink($recent['ID']) ?>" title="<?php echo esc_attr($recent['post_title']); ?>" ><?php echo $recent['post_title']; ?></a></li>to get error messages while developing your site, consider to enable DEBUG http://codex.ww.wp.xz.cn/Debugging_in_WordPress
The topic ‘wp_get_recent_posts’ is closed to new replies.