Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I Want to Add My Latest 5 Post Title with Corresponding Link in My Header Position.What was the Actual Php code?Am Newbie ....

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This sounds like an additional Loop on that page, right? You might want to use:

<ul>
    <?php $posts_query = new WP_Query('posts_per_page=5');
        while ($posts_query->have_posts()) : $posts_query->the_post();
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; wp_reset_query(); ?>
</ul>

Also read more here: http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

share|improve this answer
    
it working fine.thx Daniel –  Ramkumar Jun 20 '11 at 13:38
    
you're welcome :) –  Daniel Sachs Jun 20 '11 at 13:41
    
Note that this method incurs unnecessary overhead, because, IIRC, posts_per_page doesn't limit the number of posts returned, but rather only limits the number of posts shown per page. So, even though you're only showing 5 posts, the query returns all posts. Thus, get_posts() is considerably lighter for returning recent posts. –  Chip Bennett Jun 20 '11 at 14:56
add comment
<?php $recent_posts = get_posts('numberposts=5');
if($recent_posts) { ?>
    <ul>
        <?php foreach( $recent_posts as $recent ) { ?>
        <li>
        <a href="<?php echo get_permalink($recent->ID); ?>"><?php echo $recent->post_title; ?></a>
        </li>
        <?php } ?>
    </ul>
<?php } ?>

http://codex.wordpress.org/Template_Tags/get_posts you need to change the html tags if you need a different output.

share|improve this answer
    
thx michael.... –  Ramkumar Jun 20 '11 at 13:37
    
I prefer the get_posts() method, personally. –  Chip Bennett Jun 20 '11 at 14:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.