Forums

summaries not working in custom template (8 posts)

  1. jrbriggs
    Member
    Posted 3 years ago #

    I'm creating a custom template to display the summaries of all posts on a single page (using: <?php query_posts('showposts=-1&orderby=title&order=ASC'); ?>). All posts are being listed, but the full text rather than just the summary.

    I've even tried copying the main index template (which displays the summaries correctly) and adding the query_posts function call -- and still the full post is displayed.

    I've probably missed something obvious, so hopefully someone will be able to point out where I've gone wrong....? (Using WP2 by the way).

    Thanks in advance for any advice.

  2. alphaoide
    Member
    Posted 3 years ago #

    the_content template tag displays the full content; the_excerpt displays the summary.

  3. samboll
    moderator
    Posted 3 years ago #

    I've not ever tried this, but I know you're getting exactly what you're calling - the full post.
    Maybe take a quick glance at this page - I think it may be the direction you want to go.
    http://codex.wordpress.org/Template_Tags/the_excerpt

  4. Chris_K
    Administrator
    Posted 3 years ago #

    As mentioned, either use the_excerpt() or use the <!-- More --> tag.

    personally, I find the latter a lot easier...

  5. jrbriggs
    Member
    Posted 3 years ago #

    Sorry, I should've mentioned. All my posts are using <!--more-->, plus I've tried using the_excerpt, and it doesn't seem to work either.

    I've basically created a page (with no content), and set the template to my custom template (I've pasted the top part of it below).


    <?php
    /*
    Template Name: Display All
    */
    ?>

    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">

    <?php if (have_posts()) :
    echo "USING DISPLAY ALL TEMPLATE";
    query_posts('showposts=-1&orderby=title&order=ASC');
    ?>

    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <div class="entry">
    <?php the_excerpt(); ?>
    </div>

  6. alphaoide
    Member
    Posted 3 years ago #

    link to the page?

  7. jrbriggs
    Member
    Posted 3 years ago #

    I don't have it running on an externally accessible server unfortunately.

    Happy to post/email/whatever the full template file, if someone wants to try it for themselves. And I guess I should try a fresh WP install, and try it on that (since I've got a bunch of experimental stuff on the current install)

  8. jrbriggs
    Member
    Posted 3 years ago #

    Finally figured out the problem. I think I misread whatever reference I found that suggested using query_posts -- I assumed it loaded posts ready to use in the_loop, whereas it actually just displays them. So what I thought was a problem with the_excerpt was actually 2 different sets of behaviour:

    1) query_posts was dumping all posts into the page and,
    2) the loop code starting with while (have_posts()) : was actually returning nothing, so the_excerpt function wasn't actually being executed.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags