Archived topic
Archive Pages + Query Loops
13 replies · Started by Leanne on May 31, 2022
I'm trying to set up an archive page for a custom post type and I'm lost.
I tried using a Block > Hook > before_content and within I had my term description (via Dynamic Content block) and a query loop (GenerateBlocks - beta) set to display how I wanted my queries to display. This caused it to repeat that block 24 times for every post I had, and then still had other content within it, I'm guessing from the archive template files within GeneratePress.
Then I tried a Block > Content Template, with a container set to 33%, an image and a heading (both GenerateBlocks using dynamic content). It brings in the correct content, but the columns are all 100% wide and there's pagination, which I don't want for these CPTs.
I'm running the betas of GenerateBlocks + Pro, and the latest version of GPP.
What I need to know is:
- How best to set up the framework/layout for an archive page for a custom post type
- How to style the query loop for this CPT and remove pagination from the CPT
Can I create these with elements, or should I be working in my child theme files instead?
– How best to set up the framework/layout for an archive page for a custom post type
If we are talking about the CPT archive page, NOT a static page, then using block element - content template is the way to go.
Query loop block is used to add post loops to static pages.
The width you set in the content template won't work, you'll need this PHP filter to activate the columns for CPT, it will follow the columns number your set at customize > layout > blog.
https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type
– How to style the query loop for this CPT and remove pagination from the CPT
If you are not adding CPT post loops to a static page, you won't need query loop block.
I've got my columns working on my custom post type, I was able to get rid of pagination by setting up infinite scrolls within customizer.
My last issue is, how do I add a container around my content on the archive page for the CPT so I can set max-width, padding/margins, etc?
Can you link me to your CPT archive page?
If it's not using a specific archive template, it should follow the customizer options on spacing.
Let me know!
I added the URL to the private info.
With the customizer settings, it's making the line under my breadcrumbs go to a max-width of 1200 rather than full width.
We're likely going to have other full-width CTAs that need to go on this page as well. I added a test on at the bottom and it's also being constrained to the width set in customizer on the archive page.
What are you trying to achieve? Full width for the CPT archive? Or full width for the breadcrumbs?
The content between Collection: Kid's Room down to above where the Testing block is needs to be a contained width. Everything else should be full width.
Looking at the source, everything contained within the div generate-columns-container that's right after main class="site-main" id="main"> opens.
I guess css might be my best option then to set it?
If you want a section to be full width, don't insert them into the content container, insert them toafter_header or before_footer.
In order to make full width of the below elements:
1. Breadcrumb: block element type - hook , hook name: after_header.
2. Archive page title and description: you can use a block element - page hero to replace the original one.
3. The testing block: block element type - hook, hook name: before_footer.
Here's a hook visual guide: https://docs.generatepress.com/article/hooks-visual-guide/#posts-page
That works perfectly!!
One last question about archive pages. On the top level pages, like the 2 I shared, I want to only see the categories if there are sub-categories, but if there are no sub-categories, then it should show the posts for that category. Is there a way to do this with GeneratePress?
Hi Leanne,
To clarify, are you referring to the Breadcrumbs?: https://share.getcloudapp.com/yAu1on2X
If so, it would be best to reach out to the support of the plugin for the Breadcrumbs.
Hope this clarifies. If you’re referring to something else, kindly let us know. :)
No, not the breadcrumbs. Those are working fine.
I'm thinking more like how WooCommerce can show categories on the pages. I suspect this is outside the scope of your support though.
Because these are virtual exhibits, I need users to be able to drill down to the exhibit they want to view and then see the posts associated with that category. Right now the page is showing all posts from children categories under the parent.
You can give this PHP snippet a try:
https://generatepress.com/forums/topic/list-subcategories/#post-699132
I think that will work, or at least get me in the right direction.
Thank you so much for the assistance! I'm going to close the ticket now.
Glad to help :)