views:

36

answers:

2

Hi,

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; ?> 
+2  A: 

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;
?>
Vanco
sweet it works. I addes the links to the post as well and now need to adjust the layout using CSS. Can I add DIVs in between the PHP??<?php query_posts('showposts=3'); ?> <?php while (have_posts()) : the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><br /> <?php endwhile;?>
Andy
Although it works, it gives me the next problem:It adds all other posts to the te section?! Where it first showed only the post I requested using the permalink, now all posts are displayed as well...
Andy
To answer you first question: Yes, you can add DIVs, but be carfull where you put them - they should be inside the foreach loop, or around the loop.Please clarify your second question a bit - what section, what all posts? Do you want to use categories?
Vanco
Okay, got it with the DIVs.second question is solved, and yes I think I would like to use categories as I would like to create different kind of blogs like 'news' 'entertainment' 'sports' etc... and if a posts belongs to for example entertainment, the sidebar should only show the latest several post titles from the category entertainment. So I'm not quite sure how to do that, I'm guessing I need some IF rule in the PHP that checks to what category the post belongs to and then retrieve only the latest posts that belong to that category.
Andy
Vanco
A: 

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 ?

mireille raad