WordPress.org

Support

Support » Themes and Templates » [Resolved] Display only excerpts on home page/category pages/search results?

[Resolved] Display only excerpts on home page/category pages/search results?

  • FirstTracks
    Member

    @firsttracks

    Folks, I’m looking for some help in changing the template to only show the excerpt on the stated pages instead of the full article.

    Thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • FirstTracks
    Member

    @firsttracks

    Nevermind, I just answered my own question. For those who may be wishing to do the same, in content.php replace:

    <?php if ( is_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>', 'twentyfourteen' ) );
    			wp_link_pages( array(
    				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
    				'after'       => '</div>',
    				'link_before' => '<span>',
    				'link_after'  => '</span>',
    			) );
    		?>
    	</div><!-- .entry-content -->
    	<?php endif; ?>

    with:

    <?php if ( is_single() ) : // Only display full content for Single page ?>
    	<div class="entry-content">
    		<?php
    			the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ) );
    			wp_link_pages( array(
    				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
    				'after'       => '</div>',
    				'link_before' => '<span>',
    				'link_after'  => '</span>',
    			) );
    		?>
    	</div><!-- .entry-content -->
    	<?php else : ?>
    	<div class="entry-summary">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-summary -->
    	<?php endif; ?>
    WPyogi
    Forum Moderator

    @wpyogi

    Note that this kind of change should only be done in a child theme – otherwise the changes will be overwritten upon updating WP

    http://codex.wordpress.org/Child_Themes

    A simpler solution is to copy content.php to your child theme and change line 47 from
    <?php if ( is_search() ) : ?>
    to
    <?php if ( is_search() || is_home() ) : ?>

    Less code to add and much cleaner 🙂

    FirstTracks
    Member

    @firsttracks

    WPYogi: Of course. I made my changes in a child theme.

    Zulfikar Nore: I like the idea of smaller code of course, especially because I really don’t know what I’m doing. The problem with your solution, however, is that if I look at indexes of a specific category I’m still seeing the whole post. With my solution I’m only seeing the excerpt on the category index.

    However if you have a smaller solution that does this, too, I’m all ears!

    Ayman
    Member

    @aymanalzarrad

    @firsttracks, if you wanna apply the solution that @zulfikar Nore gave you with category archive page than you will have to add the corresponding conditional tag.
    <?php is_category(); ?>
    you can ready more about available conditional tags here:
    http://codex.wordpress.org/Conditional_Tags

    In that case the code you’d use is
    <?php if ( is_search() || is_home() || is_archive() ) : ?>

    Zulf

    ayeronnie
    Member

    @ayeronnie

    Trying to figure out what I am doing wrong. I did a child theme with all the suggestions in this thread. My posts are now excepts on the home page like I wanted, but there are no titles or anything else, just except text.

    What did I do wrong, or forget?

    Thank you in advance 🙂

    @ayeronnie,

    It would be much better and quicker to get a response if you open a new thread as this one is already marked as resolved – that’s in addition to following forum rules 🙂

    Just reference this thread and give as much details as you can and we’ll be glad to help as much as we can.

    @zulfikar Nore: Thank you so much for the information to add to the child theme. Brilliant and works like a charm!

    A simpler solution is to copy content.php to your child theme and change line 47 from
    <?php if ( is_search() ) : ?>
    to
    <?php if ( is_search() || is_home() ) : ?>
    
    Less code to add and much cleaner :)
    betholsoncreative
    Participant

    @betholsoncreative

    Just a quick secondary option if someone is looking for how to do this but doesn’t really know code that well. There is a cool free plugin called Fourteen Extended that adds extended options to the 2014 theme’s Customize panel in the dashboard.

    One of the many options is to ‘turn on’ summary/excerpts for blog posts. Works great and there are tons of other options. I use it just because it saves so much time vs. going in and changing the code myself.

    Hope that helps someone!

    How can I add a line of Google+ to the home page of my site

    @zulfikar Nore I was just looking for the same thing, an easy way to just show extracts on the archive pages. Just installed Fourteen Extended, lots of options to explore and it seems to work really nicely. Great job on this.

    @zulfikar Nore, Genius!

    Hannes Salen
    Participant

    @hannes-salen

    In the search results of my website, only the excerpts are shown, but I want the post to look like in the category view, so with the continue reading button. Anybody has an idea what I have to change in the content.php?
    I already started a sepperate thread but I got no reactions so far …

    xlightwaverx
    Member

    @xlightwaverx

    Though Fourteen Extended is a viable solution to get the Excerpt to show instead of the whole post, as of WordPress 3.9, it fails with WP-CLI with this error:

    PHP Fatal error: Call to undefined function wp_is_mobile() in /home/sitename.com/wp-content/plugins/fourteen-extended/inc/fourteenxt-customizer.php on line 633

    Deactivating Fourteen Extended allows WP-CLI to work again.

    Just letting you know so you don’t bork your sites after the 3.9 upgrade.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘[Resolved] Display only excerpts on home page/category pages/search results?’ is closed to new replies.