- This topic has 5 replies, 3 voices, and was last updated 6 years, 7 months ago by Tom.
-
AuthorPosts
-
June 9, 2017 at 6:15 am #331031Matt
Trying to include events within the loop by using the following code in functions.php:
/*-----------------------------------------------------*/ /** Add calendar events to loop **/ /*-----------------------------------------------------*/ function add_post_types_to_loop($query) { if ($query->is_main_query() && $query->is_front_page()) { $query->set('post_type', array('post', 'ai1ec_event')); } } add_action('pre_get_posts', 'add_post_types_to_loop');
This works, but breaks the front page, which displays the Blog, with the first post as the full width. Instead, it displays all the events as full width, breaking the site layout. Any ideas on how to get custom posts included in the loop without breaking the “first post full width” feature?
June 9, 2017 at 10:49 am #331166TomLead DeveloperLead DeveloperHi Matt,
You may need to enable columns within your post type as well: https://docs.generatepress.com/article/using-columns-in-the-blog/
Your conditional might be:
if ( ! is_single() && 'ai1ec_event' == get_post_type() ) { return true; }
Just a guess – worth a shot π
June 9, 2017 at 11:04 am #331175MattYou rock! This did it:
/*-----------------------------------------------------*/ /** Add calendar events to loop **/ /*-----------------------------------------------------*/ function add_post_types_to_loop($query) { if ($query->is_main_query() && $query->is_front_page()) { $query->set('post_type', array('post', 'ai1ec_event')); } } add_action('pre_get_posts', 'add_post_types_to_loop'); /*-----------------------------------------------------*/ /** Add columns to event post type **/ /*-----------------------------------------------------*/ add_filter( 'generate_blog_columns','tu_event_columns' ); function tu_event_columns( $columns ) { if ( ! is_single() && 'ai1ec_event' == get_post_type() ) { return true; } return $columns; }
I’ve got to say I’ve been working with WordPress for many, many years now and you are BY FAR the most responsive person I’ve ever run across. Thanks!!!
June 9, 2017 at 6:52 pm #331332TomLead DeveloperLead DeveloperAwesome! Glad I could help π
September 21, 2017 at 11:19 am #389569JanGreat! With a very slight mod this fixed a similar problem with The Events Calendar from Modern Tribe. That plugin has a built-in option for adding events to the main blog loop, but once enabled, I got the oversized event entries messing up the front page columns.
Putting this in my child themes functions.php seems to have fixed this:
/*-----------------------------------------------------*/ /** Add columns to event post type **/ /*-----------------------------------------------------*/ add_filter( 'generate_blog_columns','tu_event_columns' ); function tu_event_columns( $columns ) { if ( ! is_single() && 'tribe_events' == get_post_type() ) { return true; } return $columns; }
Please note, I have absolutely no idea what I’m doing, so this was a lucky shot.
September 21, 2017 at 11:41 pm #389790TomLead DeveloperLead DeveloperGood code! Thanks for sharing π
-
AuthorPosts
- You must be logged in to reply to this topic.