Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a custom wordpress theme. Then I created a new page template called "blog." I used this to load all the posts but unfortunately it only loads one blog post.

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>"
    title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <small>on <?php the_time('M d'); ?> tagged <?php the_tags(''); ?> by <?php the_author_posts_link(); ?></small>
    <?php the_content('Read More'); ?>
    <div class="separator biggap"></div>
    <?php endwhile ?>
    <div id="posts_navigation">
        <?php previous_posts_link(); ?>
        <?php next_posts_link(); ?>
    </div>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for
    something that isn't here.</p>
<?php endif; ?>
share|improve this question
Is there a reason you can't use the default blog functionality and style your content using the home.php file? – mrwweb May 14 '12 at 14:55

closed as not a real question by toscho Jul 20 '12 at 23:44

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

You shuld actually do it a little but different... i presume you know how to create a Custom page template AKA:

<?php
/*
Template Name: 50 Recent
*/
?>

. Then, The loop should include the amount of posts you want to retrive like so..
(i have builg it in a list form but you change that to div's or what not)

<!--======== Main Loop ============-->
<div class="mainloop">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="singlepost">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>

<!--== recent posts ==-->
<ul>
<?php
$args = array( 'numberposts' => '50' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' .   $recent["post_title"].'</a> </li> ';
}
?>
</ul>

</div>
<?php endwhile; else: ?>
<p> <?php _e('Sorry, no posts matched your criteria.'); ?> </p>
<?php endif; ?>
</div>
</div>  

.
* You can Change the number of posts in this line:

   $args = array( 'numberposts' => '50' );

.
Or add additional arguments..

.

Hope this helps..

share|improve this answer
If you're using wp_get_recent_posts, then that should not appear in the loop. Looking at your code, I believe that for each post in the real loop, it would echo its own permalink in a list item 50 times. – mrwweb May 14 '12 at 15:43
You are mistaken. this works. taken from a working page i created a long while ago. try it before you judge. a quick look and its easy to see its constructed well. -> get_permalink($recent["ID"]) this a custom value permalink... – Sagive SEO May 14 '12 at 19:23
Ok. I overlooked that, you're right that it will work. But still, it's an odd use of the loop just to get the_title(). I'd use global $post; $post->title; and keep the loop out of it. (And in general, why not just use the default blog setup that ships with WordPress core?) – mrwweb May 14 '12 at 19:44

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