Skip Navigation

[Resolved] How to display CPT archive to match default Generatepress layout (masonry)

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#1994959

Tell us what you are trying to do?

I use the pro Generatepress theme (with GP Premium plugin). This theme allows the display of the post archive page as a two-column masonry grid. I've created a few custom post types and I want them to follow the same archive layout as posts.

Is there any documentation that you are following?

I'm using the code from this page: hidden link

I added the following code via Toolset's Custom Code Snippets feature:

//////////////

add_filter( 'generate_blog_masonry','qa_faqs_masonry' );
function qa_faqs_masonry( $columns ) {
if ( is_post_type_archive( 'FAQ' ) ) {
return true;
}

return $masonry;
}

////////////

My CPT Name: FAQ
My CPT slug: qa_faqs

Is there a similar example that we can see?

This is the masonry layout for normal posts:
hidden link

Any time an FAQ post type appears in the archive list, it messes up the layout.

What is the link to your site?

This is the archive for my FAQ cpt:

hidden link

The posts should be displayed in a two column masonry grid. What am I missing?

#1995695

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

I've noticed a couple of points about the snippet that you've shared:

1. In the function's name (line# 2), it is using the "$columns" parameter, but at the end (line# 7), it is returning the "$masonry" variable, which is not defined anywhere. They both should be the same variables.

2. Within the "is_post_type_archive( )", the post type's slug should be used: is_post_type_archive( 'qa_faqs' ).
( ref: https://developer.wordpress.org/reference/functions/is_post_type_archive/ )

3. The conditional check for the "is_post_type_archive( 'qa_faqs' )" would only apply to the FAQ post type's archive page, which is at:
{yourwebsite.com}/qa_faqs/

The page that you're trying to target is the category archive page for the term "FAQ":
{yourwebsite.com}/category/faq/

To target that archive page, you'll need to use "is_category( )" conditional check:
https://developer.wordpress.org/themes/basics/conditional-tags/#a-category-page

Example of the snippet that should work for both those archive pages:


add_filter( 'generate_blog_masonry','qa_faqs_masonry' );
function qa_faqs_masonry( $masonry ) {
    if ( (is_post_type_archive( 'qa_faqs' )) || (is_category( 'faq' )) ) {
        return 'true';
    }

    return $masonry;
}

regards,
Waqar

#1995787

Thanks Waqar. That works.

I've added it as a custom code snippet in Toolset. Which setting should I use?

Run mode: "Always" or "On demand"

Run context: "Front-end / WordPress admin / AJAX calls"

#1995807

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad I could help.

For "Run mode", you can select "Run always" and for "Run context", you can select "Front-end".
( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ )

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.