Community Forums › Forums › Archived Forums › General Discussion › Adding CPT to Genesis Post
Tagged: blog post, CPT homepage
- This topic has 9 replies, 3 voices, and was last updated 9 years, 8 months ago by Brad Dalton.
-
AuthorPosts
-
July 23, 2014 at 7:04 pm #115626jholcombkwMember
I am wanting to add a CPT to the homepage along with Posts. Currently we have Post which equal Cat-1 pulling on the homepage newest to oldest and I would like to mix in a CPT.
The current code is on functions.php
/*** Custom Post Byline */ function custom_post_info($post_info) { $post_info = 'By [post_author_posts_link]'; if (!is_single()) { $post_info .= '<a href="' . get_comments_link() . '" class="leave-comment">Leave a Comment</a>'; } $post_info .= '<div class="post-date"><span class="month">[post_date format="M"]</span><span class="day">[post_date format="j"]</span>[post_comments zero="0" one="1" more="%"]</div>'; return $post_info; } add_filter('genesis_post_info','custom_post_info',40); add_filter('genesis_post_info','do_shortcode',40);
Current homepage php
<?php remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'child_grid_loop_helper' ); /** Add support for Genesis Grid Loop **/ function child_grid_loop_helper() { if ( function_exists( 'genesis_grid_loop' ) ) { remove_action( 'genesis_before_post_content', 'generate_post_image', 5 ); genesis_grid_loop( array( 'cat' => 1, 'features' => 1, 'feature_content_limit' => 0, 'grid_image_size' => '', 'grid_content_limit' => 0, 'more' => __('Continue','inspyr'), ) ); } else { genesis_standard_loop(); } } genesis();
How would I add a CPT?
http://theozarksconnection.comJuly 23, 2014 at 7:24 pm #115631Brad DaltonParticipantYou could try something like this http://wpsites.net/wordpress-tips/include-different-post-types-in-home-page-loop/
July 23, 2014 at 8:57 pm #115639jholcombkwMemberI tried the code, but nothing worked.
July 23, 2014 at 9:10 pm #115642Brad DaltonParticipantWhere did you add the code?
Did you change the post name in the code to the name of your CPT?
The code is tested and works.
July 23, 2014 at 9:31 pm #115646jholcombkwMemberI add it to the bottom of my home.php and then tried it at the bottom of my functions.php. Yes I changed
add_action( 'pre_get_posts', 'wpsites_add_custom_post_types_to_loop' ); function wpsites_add_custom_post_types_to_loop( $query ) { if ( is_home() && $query->is_main_query() && !is_admin() ) { $query->set( 'post_type', array( 'post', 'your-cpt' ) ); return $query; } }
To
add_action( 'pre_get_posts', 'wpsites_add_custom_post_types_to_loop' ); function wpsites_add_custom_post_types_to_loop( $query ) { if ( is_home() && $query->is_main_query() && !is_admin() ) { $query->set( 'post_type', array( 'post', 'events' ) ); return $query; } }
July 23, 2014 at 10:59 pm #115652essaysnarkParticipantI don't know how you have your CPT set up but it might need to be 'event' not 'events'.
July 24, 2014 at 12:03 pm #115723jholcombkwMemberThe CPT is events and it pull it. Where should I add the code?
July 24, 2014 at 12:13 pm #115724Brad DaltonParticipantCopy one of these snippets from the view raw link in the Gist and paste it at the end of your child themes functions file using a code editor.
July 24, 2014 at 12:21 pm #115728jholcombkwMemberIs there away to filter out only Category you want? Category id = 1 than pull to homepage?
July 24, 2014 at 12:50 pm #115736Brad DaltonParticipantPlease mark this as resolved and start a new topic for your 2nd question.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.