Community Forums › Forums › Archived Forums › Design Tips and Tricks › Grid loop (Bill Erickson version) – content limit for features
Tagged: content limit, Excerpt, grid loop
- This topic has 3 replies, 2 voices, and was last updated 11 years ago by
Dorian Speed.
-
AuthorPosts
-
February 12, 2013 at 8:29 pm #19985
Dorian Speed
MemberThis 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 #20425billerickson
MemberDid 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 #20426Dorian Speed
MemberHey, 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 #86997Dorian Speed
MemberI 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! -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.