tags:

views:

61

answers:

2

I need to add links to WordPress Posts on a static HTML page. I got some information that has been helpful but need a few more elements to make it complete.

Here is the code I have so far:

<?php

$number = 5;
$wordpress_header = "blog/wp-blog-header.php";

      // Include wordpress header   
      if (file_exists($wordpress_header))
       {
         include ($wordpress_header);

        $myposts = get_posts('numberposts=$number&offset=0&category=0');

        echo "<ul class='Bloglinks'>";

        foreach(array_slice($myposts, 0, $number) as $post) 
         {
            echo '<li><a href="';
            the_permalink();
            echo '">';
            the_date();
            echo " ";
            the_title();
            echo '</a></li>';
         }

         echo "</ul>";

       }
       else
       {
         echo "Unable to connect to Wordpress header file.";
         die();
       } 

?>  

This only shows the titles of the most recent posts. I need to be able to display the following:

<h5>The truth about Lazy Eye</h5>
<p class="blog-info">07.16.10 | <a class="comment-ref">3 Comments</a></p>
<h5>More Adult Learning Problems Linked to Eyes</h5>
<p class="blog-info">06.12.10 | <a class="comment-ref">1 Comments</a></p>
<h5>New Vision Examination Instruments Arrived!</h5>
<p class="blog-info">05.10.10 | <a class="comment-ref">13 Comments</a></p>
+1  A: 

You should use the function query_posts() with the functions have_posts() and the_post(). Here is an example for the WordPress API:

//The Query
query_posts('posts_per_page=5');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
 ..
endwhile; else:
 ..
endif;

//Reset Query
wp_reset_query();

That will loop through all posts you have queried. So you can just insert your query from the get_posts() function into the query_posts() function.

EDIT: I think if you want to stick with the get_posts() function, you have to call the setup_postdata() function to get the new post (source code for the API):

<ul>
    <?php
        global $post;
        $myposts = get_posts('numberposts=5&offset=1&category=1');
        foreach($myposts as $post) :
            setup_postdata($post);
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
</ul> 

But I would recommend to take the query_posts() function instead.

Kau-Boy
A: 

I am running into a similar problem.. I have wordpress included in a phpbb forum (so I can use the adtracking plugin from WP) but I find that wordpress is rewriting some links in phpbb.

tomcat23