• 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

Grid loop (Bill Erickson version) – content limit for features

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 › Grid loop (Bill Erickson version) – content limit for features

This topic is: not resolved

Tagged: content limit, Excerpt, grid loop

  • This topic has 3 replies, 2 voices, and was last updated 9 years ago by Dorian Speed.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • February 12, 2013 at 8:29 pm #19985
    Dorian Speed
    Member

    This isn't Genesis-specific, I guess, but I'm curious as to whether anyone has implemented Bill's better, easier grid loop with one content limit for the features and another for the teasers. I know there's a plugin for the grid loop but I am inserting some custom post types into the loop so I don't think that would work with the plugin.

    I found this code that works with the plugin but it didn't work with the grid loop code from his original blog post, as far as I could tell. I feel like the issue is with the filter but I'm not sure where to go from there.

    /**
     * Grid Content
     * Change the number of words in excerpt if in the grid loop
     */
    function be_grid_content() {
     
    	// First, we make sure we're in the grid loop.
    	if( ! apply_filters( 'is_genesis_grid_loop', false ) )
    		return;
     
    	// Change length if teaser
    	if( in_array( 'teaser', get_post_class() ) )
    		$length = 20;
    	else
    		$length = 55;
     
    	echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '</p>';
    }
    add_action( 'genesis_post_content', 'be_grid_content' );
    remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    

    This is a general question, not specific to a particular site at this point.


    Bringing websites Up to Speed
    Firebug will light the way to understanding the secrets of the Internet!

    February 14, 2013 at 5:56 pm #20425
    billerickson
    Member

    Did my response to your comment on my blog not work? Here's what I said:

    Try this instead: https://gist.github.com/billerickson/4947529

    The filter in the previous link doesn’t exist in the advanced example above, only the plugin.

    You can use the plugin with custom post types by using the ‘genesis_grid_loop_sections’ filter (http://www.billerickson.net/code/limit-genesis-grid-to-specific-category/ ). I prefer to use the plugin rather than the advanced example above to keep the theme simpler.

    February 14, 2013 at 6:01 pm #20426
    Dorian Speed
    Member

    Hey, thanks! I actually haven't had a chance to implement your suggested code yet. I posted this around the same time as I commented on your blog because I figured if someone else had a quick answer I could go back and say "never mind, here's what worked, thanks for your time." Instead, it appears I have pestered you in two locations. 🙂

    I will come back and post here after trying this out. Thought it would be good to have the information here on the forums as well as on your site in case people weren't aware of your original tutorial.


    Bringing websites Up to Speed
    Firebug will light the way to understanding the secrets of the Internet!

    January 25, 2014 at 2:51 pm #86997
    Dorian Speed
    Member

    I realized I never came back to this thread to post the solution. Credit goes to Bill Erickson and Brandon Kraft for assistance with this. Here's the entirety of the front-page.php file I used (site is http://hisrocketman.com) to implement a grid loop with one limit for features and a different limit for teasers.

    <?php
    /**
     * Front Page
     *
     * @author       Bill Erickson <[email protected]>
     * @copyright    Copyright (c) 2011, Bill Erickson
     * @license      http://opensource.org/licenses/gpl-2.0.php GNU Public License
     *
     */
    
    function custom_excerpt_length( $length ) {
    	return 500;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999);
    
    /**
     * Grid Content
     * Change the number of words in excerpt if in the grid loop
     */
    function be_grid_content() {
     
    	// First, we make sure we're in the grid loop.
    	if( ! apply_filters( 'is_genesis_grid_loop', false ) )
    		return;
     
    	// Change length if teaser
    	if( in_array( 'one-half teaser', get_post_class() ) ) {
    		$length = 40;
    		}
    	else {
    		$length = 200;
    		 //print_r(get_post_class());
    }
     
    	echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '<a class="more-link" href="' . get_permalink() . '" rel="nofollow">[Continue Reading]</a>' . '</p>';
    	// Remove default content so we don't get both
    	 remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    }
    
    add_action( 'genesis_post_content', 'be_grid_content', 9 );
    
    /**
     * Remove Post Meta on Teasers
      */
    function be_archive_post_meta( $post_meta ) {
    	if( in_array( 'one-half teaser', get_post_class() ) )
    		remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
    		remove_action( 'genesis_before_post_content', 'genesis_post_info' );
    }
    
    add_action('genesis_before_post', 'be_archive_post_meta');
    
    genesis();
    ?>

    Bringing websites Up to Speed
    Firebug will light the way to understanding the secrets of the Internet!

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 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

© 2023 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