Site logo

Archived topic

All-in-One Event Calendar & Blog Layout

5 replies · Started by Matt on June 9, 2017

Viewing posts 1–6 of 6

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?

You 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!!!

Awesome! Glad I could help :)

Great! 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.

Good code! Thanks for sharing :)

This archived topic is closed to new replies.