WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excerpts only for all posts (12 posts)

  1. Peeekay
    Member
    Posted 2 years ago #

    Hi,

    I've been searching for an answer on how to display the exceprt of a post automatically rather than the entire post. After searching I found its simply a matter of changing the replace the <?php the_content; ?> with <?php the_excerpt(); ?> in the index page in the appearance editor.

    I just cant seem to find it on the index.php file.

    Here's what the file shows

    [code moderated - please follow the forum guidelines for posting code; in case of an original template from Twenty Eleven, there is no need to post the code at all]

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    this line
    <?php get_template_part( 'content', get_post_format() ); ?>
    is pointing to
    content.php
    where you will find this section:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>

    btw:
    if you have not already, please consider creating a child theme http://codex.wordpress.org/Child_Themes to make the edits there; don't edit the default theme Twenty Eleven directly, as it is important to have an unedited default theme in case of problems. also, a child theme helps to keep the customisations which will otherwise be overwritten with the next upgrade of your wpordpess version.

  3. peredur
    Member
    Posted 2 years ago #

    Firstly, you should never alter any default theme without doing so in a Child Theme.

    Secondly, there is a way of creating a teaser on a post-by-post basis by using the 'more' tag in the visual editor (the button to the right of the unlink button).

    Thirdly, the_excerpt() strips HTML formatting from the teaser.

    However, if you want to go ahead after all that you need to copy IIRC the file loop.php into your child theme and make the change in the appropriate place.

    HTH

    PAE

  4. Peeekay
    Member
    Posted 2 years ago #

    Thanks for the reply. So I should change the

    <?php get_template_part( 'content', get_post_format() ); ?>

    to what exactly?

  5. Peeekay
    Member
    Posted 2 years ago #

    Oh and peredur I choose not to use the 'more' tags as these are users submitted posts through gravity forms.

  6. Peeekay
    Member
    Posted 2 years ago #

    Think I got it. Can anyone confirm if this is correct. Im pretty new to wordpress and php.

    I replaced the

    <?php get_template_part( 'content', get_post_format() ); ?>

    with this

    <?php the_excerpt(); ?>

    Anyone have an idea of how to automatically include a thumbnail with each excerpt?

  7. peredur
    Member
    Posted 2 years ago #

    No. You need to alter content.php (in a child theme if you don't want a WP update to overwrite your changes).

    I didn't remember correctly. It's twentyten that uses loop.php.

    HTH

    PAE

  8. Peeekay
    Member
    Posted 2 years ago #

    I'm not really understanding what I'm supposed to change: You're telling me to alter the content.php to what exactly?

    So this is my content/.php
    http://pastebin.com/1NqAFG3K

    What do I need to change it to?

    Thanks
    `

  9. Peeekay
    Member
    Posted 2 years ago #

    Figured it out here

  10. alchymyth
    Forum Moderator
    Posted 2 years ago #

    for example, change line 41 in content.php from:

    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>

    to:

    <?php the_excerpt(); ?>
  11. peredur
    Member
    Posted 2 years ago #

    Addressing your point about a thumbnail...

    I believe there's a way of modifying the default behaviour although I've not been able to find it but by default, as I said in an earlier post, the_excerpt() removes HTML from the excerpt. As I understand it, this includes <img> tags.

    Cheers

    PAE

  12. Scott@adszoom
    Member
    Posted 2 years ago #

    <?php else : ?>
    		<div class="entry-content">
    			<?php the_excerpt( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>

    like this ? works for me but just to conf... how about showing the thumb nail in the excerpt ?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags