开发者

error wordpress, adjusted sidebar.php to show latest 10 posts

I'm trying to edit my sidebar.php file in my current them WP is using to display the last # of posts (only the titles) as links.

I tried using the example of http://codex.wordpress.org/Integrating_WordPress_with_Your_Website but I always get the error on the line that states where the file wp-blog-header can be found.

the error when opening the index blog page where the sidebar should be shown:

// Get the last 3 posts. Warning: require(/blog/folder/wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /blog/folder/wp-content/themes/default/sidebar.php on line 7

So what is wrong? Is there a way to permanently embed a function in my html template page that retrieves the latest few posts everytime an article is displayed on the template page?

the code:

<?php require('/the/path/to/your/wp-blog-header.php'); ?> 
<?php $posts = get_posts('numberposts=10&order=ASC&orderby=post_title'); foreach ($posts as $post) : start_wp(); ?> 
<?php the_title开发者_开发知识库(); ?> 
<?php the_excerpt(); ?> 
<?php endforeach; ?> 


You don't need the require. Also, I've cleaned up the code a bit. Try this and tell me does it work.

<?php
   $posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
   foreach ($posts as $post) :
      start_wp();
      the_date();
      echo "<br />";
      the_title();
      the_excerpt();
   endforeach;
?>


How about using this one liner :

<?php wp_get_archives('title_li=&type=postbypost&limit=10'); ?>

all you have to do is post it in sidebar.php

neater, no ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜