Site logo

Archived topic

Issue with web-stories archive page

10 replies · Started by Hilton on June 26, 2022

Viewing posts 1–11 of 11

Hello, I use the web-stories plugin and I'd like to know how can I customize web-story archive page so ir can display 3 columns with pagination, as this one https://bit.ly/3bua7LM . This is how my current page is looking like https://bit.ly/39R39An . Thanks

Hi Hilton,

You’ll need a PHP snippet to add columns to your CPT: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type

There’s also a code here to change the number of columns.

So, yours would be:

add_filter( 'generate_blog_columns', function( $columns ) {
    if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) {
        return true;
    }

    return $columns;
} );

and

add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
   if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) {
        return 33;
    }

    return $count;
}

Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

Hope this helps!

Hello, I don't know if you've seen the web stories archives page, which is this one https://bit.ly/39R39An . I need a specific function for that archives page, which in this case is mywebsite.com/web-stories . Your function doesn't seem to be specific to this page.

Hi David,

Looks like it was a great start. But first of all, this web-stories archives page is the only one on the site that will be using columns, so I believe it needs an add-on to this function. Another thing is that I would like the web-stories archive page to display only the stories, in 3 columns, and not the same format of the other archive pages, where the image, title and excerpt appear.

https://bit.ly/3OOJY8Y

Thanks!

Hi David,

That is great! My page looks exactly the way I expected https://bit.ly/3AgFl3m

I added the following functions, hope it help other users:

add_filter( 'generate_blog_columns', function( $columns ) {
    if ( ! is_singular() && 'web-story' === get_post_type() ) {
        $columns = true;
    }

    return $columns;
} );
add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
    if ( ! is_singular() && 'web-story' ) {
        return 33;
    }

    return $count;
}
add_filter( 'get_the_archive_title', function ( $title ) {
    if ( 'web-story' === get_post_type() ) {
        $title = 'Web Stories';
    }
	return $title;
},50);

David,

Just one more question, if I wanted to add the same layout to another custom post type named "video", how can I change the function above to make it working for both ("web-stories" and "video"). Should I use an array?

Thanks

Awesome - yeah you can use an array fro example:

add_filter( 'generate_blog_columns', function( $columns ) {
    $post_types = array(
        'web-story',
        'video'
    );
    if ( ! is_singular() && in_array( get_post_type(), $post_types )  ) {
        $columns = true;
    }

    return $columns;
} );

Thanks David! You are the best!!

Glad to be of help

This archived topic is closed to new replies.