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

Community Forums Forums Design Tips and Tricks Grid loop (Bill Erickson version) – content limit for features

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Dorian Speed 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19985

    Dorian Speed
    Participant
    Post count: 140

    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.
    [php]
    /**
    * 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’ );
    [/php]

    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!

    • This topic was modified 1 year, 5 months ago by  Dorian Speed.
    • This topic was modified 1 year, 5 months ago by  Dorian Speed.
    #20425

    billerickson
    Participant
    Post count: 16

    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.

    #20426

    Dorian Speed
    Participant
    Post count: 140

    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!

    #86997

    Dorian Speed
    Participant
    Post count: 140

    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 <bill@billerickson.net>
     * @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!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.