WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Twenty Twelve: Excerpts on Home/Tag/Category pages (15 posts)

  1. OperaManiac
    Member
    Posted 1 year ago #

    I understand that search results already show excerpts. How to do the same for homepage, tag pages, author pages and category pages?

    Basically want to show complete post only on individual post pages.

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    edit content.php (ideally after you have created a child theme http://codex.wordpress.org/Child_Themes) and change this line:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>

    and include any other conditional tags such as 'is_archive()' and/or 'is_author()' etc.

    http://codex.wordpress.org/Conditional_Tags

    example:

    <?php if ( is_search() || is_archive() || is_author() ) : // Only display Excerpts for Search ?>
  3. OperaManiac
    Member
    Posted 1 year ago #

    ah thanks. i ended up using a plugin which did the job for me. but yeah, thanks for pointing out the relevant code. all the time i was checking for code for generating these individual pages (like in the good old days!). i wish there were more documentation for such edits in the theme files.

    i am already using a child theme. would implement these changes and get rid of the plugin!

  4. janefriedman
    Member
    Posted 1 year ago #

    [nevermind - fixed]

  5. OperaManiac
    Member
    Posted 1 year ago #

    so the directions above are correct? i have not tried them out yet!

  6. blitz999
    Member
    Posted 1 year ago #

    Slight typo in there…

    To use alchmyth's start point and to answer the original q:

    <?php if ( is_search() || is_archive() || is_author() || is_tag || is_home () ) : // display excerpts for search, archives, author, tags and, most definitely home ?>

  7. Vivek Nath.R
    Member
    Posted 1 year ago #

    Thanks blitz999 for the exact code :)

  8. Arley McBlain
    Member
    Posted 1 year ago #

    @blitz999 you missed a () on is_tag. Reposting for future skimmers!

    <?php if ( is_search() || is_archive() || is_author() || is_tag() || is_home() ) : // Only display Excerpts  ?>

    Thanks for posting!

  9. blitz999
    Member
    Posted 1 year ago #

    Ooph! Mortally embarrassed, well spotted Arley!

  10. Alex
    Member
    Posted 1 year ago #

    @Arley thank you for posting. One thing I noticed is that after modifying my content.php file (in a child theme) with your code, longer posts that don't have an excerpt became truncated on the main blog page. Is there a way to display the full post on the main blog page if no excerpt is defined?

    Thanks again.

  11. blitz999
    Member
    Posted 1 year ago #

    Hi Alex, yes, easy!

    You just need to remove the

    || is_home() )

    bit of the code ;-)

  12. Alex
    Member
    Posted 1 year ago #

    Hi Blitz,

    That didn't work. The long posts without an excerpt are now showing the entire entry (good!) but now any post with an excerpt is also showing the entire entry (instead of just the excerpt.)

    Hope that made sense.

  13. blitz999
    Member
    Posted 1 year ago #

    Hi Alex, I don't follow… Happy to help, but maybe provide a link or screengrab.

  14. Alex
    Member
    Posted 1 year ago #

    Hi Blitz,

    Sorry, I should have done that up-front. I've setup a demo install that illustrates the problem here.

    As you can see, even though Post 1 is 3 paragraphs long it's getting truncated around the 4th sentence of the first paragraph. This post does not have an excerpt.

    Post 2 is the same lorem ipsum (3 paragraphs) but with an excerpt. This post is displaying correctly.

    Post 3 is a short post with only 3 sentences (and no excerpt). This is also displaying correctly, although if I add another sentence and it will get truncated like the 1st post.

    What I'm looking to do is display the entire post if no excerpt is defined, meaning Post 2 should show all 3 paragraphs on the main page.

    Hopefully this helps. I really appreciate you taking the time to assist.

  15. sivaji.siva09
    Member
    Posted 1 year ago #

    I used the same code <?php if ( is_search() || is_archive() || is_author() || is_tag() || is_home() ) : // Only display Excerpts ?> But not getting 55 words excerpt, it is only showing the title in the home, in pages, in the author and another thing is individual posts page showing only the title if use the above code and delete the <?php the_excerpt(); ?> if use both of these codes in their respective places i am getting excerpt in individual post pages and only the title in archive, author, and home. How can i achieve the exact functionality of the mentioned code. That is home, search, archive, author, and tag showing excerpts and individual post pages showing full post. How can i achieve this. Am i doing anything wrong, please help me. My website is http://www.investmentstandard.inAnd individual post page http://www.investmentstandard.in/economic-trend-investment-strategy/ Please someone help me.

Topic Closed

This topic has been closed to new replies.

About this Topic