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 have found some code to display all posts in a page but it's not exactly what I need.

What I need to do is for example:

<h1>This is the Title</h1>

<p>This is the content of the posts. It displays part of the content only.
User need to click the More! link below to view the whole post.</p>

<a href="...">More!</a>

This code I found only displays the date and the title as a link.

Here is the code:

<?php
$debut = 0; //The first article to be displayed
?>
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php
$myposts = get_posts('numberposts=-1&offset=$debut');
foreach($myposts as $post) :
?>
<li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endwhile; ?>
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

That's because the code you listed only includes a reference for the title and the link. Here's your original code, annotated ...

Original

<?php $debut = 0; //The first article to be displayed ?>

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

<!-- Display the title of the current page that's listing your posts -->
<h2><?php the_title(); ?></h2>

<!-- Create an unordered list to display a list of posts -->
<ul>

    <!-- Get a list of all posts, not including the first post -->
    <?php $myposts = get_posts('numberposts=-1&offset=$debut');

    // Loop through each post that your just grabbed
    foreach($myposts as $post) : ?>

        <!-- Add a list element for the post -->
        <li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
</ul>

<?php endwhile; ?>

This will create a block that looks something like this:

<ul>
    <li>5/2/2012: <a href="">Post title</a></li>
    <li>5/2/2012: <a href="">Post title</a></li>
</ul>

What You Should Do Instead

You just need to update your post template. Right now, it's grabbing the posts and outputting the date published, a link, and the title. So replace everything inside the <ul> ... </ul> with this:

<div class="post-list">
    <?php $myposts = get_posts( 'numberposts=-1&offset=$debut' );
    foreach( $myposts as $post) : setup_postdata( $post ) ?>
        <h1><?php the_title(); ?></h1>

        <!-- Only display part of the post so the user has to click "More!" -->
        <?php the_excerpt(); ?>

        <a href="<?php the_permalink(); ?>">More!</a>
    <?php endforeach; ?>
</div>
share|improve this answer
    
Thanks very much for this ... just got 1 problem ... the the_excerpt doesn't show at all....Any ideas why? –  user159500 May 4 '12 at 6:09
    
I've added a call to setup_postdata() in case the post's content and excerpt aren't being set up right. But anything beyond this, and you'll need some serious hands-on debugging of your site. I recommend you open a thread in the support forums for ongoing support ... this site isn't a support forum. –  EAMann May 4 '12 at 13:26
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.