[Resolved] All-in-One Event Calendar & Blog Layout

Home Forums Support [Resolved] All-in-One Event Calendar & Blog Layout

Home Forums Support All-in-One Event Calendar & Blog Layout

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #331031
    Matt

    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?

    #331166
    Tom
    Lead Developer
    Lead Developer

    Hi 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 πŸ™‚

    #331175
    Matt

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

    #331332
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad I could help πŸ™‚

    #389569
    Jan

    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.

    #389790
    Tom
    Lead Developer
    Lead Developer

    Good code! Thanks for sharing πŸ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.