• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to do conditional post excerpt vs. full content based on category?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to do conditional post excerpt vs. full content based on category?

This topic is: not resolved

Tagged: archives, categories, post excerpts

  • This topic has 4 replies, 3 voices, and was last updated 11 years, 8 months ago by tinymachine.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • October 4, 2013 at 12:41 pm #65384
    tinymachine
    Member

    I want the majority of my posts to show as an excerpt on an archive page, but I am using a category called "courses" for a specific purpose and want to always show the full content, even when on an archive page.

    Does anyone have a code snippet for this or something similar? I've been through the tutorials and code snippets provided and can't find anything even close. I know how to do this directly in a regular theme, using wordpress functions, but I'm not yet familiar enough with how genesis works to figure this out.

    My other alternative is to convert course posts to pages, but I lose a bit of functionality that way that I'd rather not have to lose if possible. Thanks in advance.

    http://brooklinetaichi.org/freshwp/category/courses/
    October 5, 2013 at 12:19 pm #65482
    David Chu
    Participant

    Hi,
    This seemed like a pretty little problem, so I gave it a try. I didn't have any luck doing Genesis commands, although one could make a custom loop to replace the Genesis loop without too much difficulty. There are tutorials on that here and there.

    I did figure out a way to do it using code I had laying around for altering the normal WP excerpt. It's probably taking the long way home, though. 🙂 It can go in your functions.php. The code sets a default word length, which you can obviously change. And you will see that I just made a much longer excerpt for a particular category - this number could be bigger if yu have really long Posts. You will also see that I changed the "read more" text, and you could alter that to taste.

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'improved_trim_excerpt');
    function improved_trim_excerpt($text) {
            if ( '' == $text ) {
                    $text = get_the_content( get_the_ID() );
                    $text = apply_filters('the_content', $text);
                    $text = str_replace(']]>', ']]>', $text);
                    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                    $text = strip_tags($text, '<p>');
    
    		$excerpt_length = 50;
    		if ( in_category('2') ) {
                    	$excerpt_length = 1000;
    		}
    
                    $words = explode(' ', $text, $excerpt_length + 1);
                        $daveLink = ' &nbsp;...[<a>Read More</a>]';
                    if (count($words)&gt; $excerpt_length) {
                            array_pop($words);
                            array_push($words, $daveLink);
                            $text = implode(' ', $words);
                    }
            }
            return $text;
    }
    

    Enjoy, Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    October 6, 2013 at 12:38 am #65522
    Sridhar Katakam
    Participant

    http://sridharkatakam.com/display-full-content-category-pages-selected-categories-genesis/


    Genesis Tutorials | Follow me on Twitter

    October 6, 2013 at 4:50 pm #65593
    David Chu
    Participant

    Yeah, check out Sridhar's stuff... he writes some great material!


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    October 6, 2013 at 4:53 pm #65594
    tinymachine
    Member

    Yes...I just did! Thank you both for the replies....all very helpful

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble