Site logo

[Resolved] Create custom category page with Generate Blocks

Home Forums Support [Resolved] Create custom category page with Generate Blocks

Home Forums Support Create custom category page with Generate Blocks

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #1673497
    Ales

    Hi,

    I would need to create a custom category page. Is that possible with Generate Blocks Pro?

    I need to create an article as a category with no latest posts showed and a category with some custom blocks at the top, and then below with the latest posts.

    Is it possible to do this with Generate Blocks Pro?

    Thanks!
    Alex

    #1673574
    David
    Staff
    Customer Support

    Hi there,

    You can use a Block Element to hook in any content you want above the list of posts on standard category archive page:

    https://docs.generatepress.com/article/block-element-overview/

    In GPP 2.0 Alpha that content can include dynamic data:

    https://generatepress.com/introducing-the-gp-theme-builder/

    #1677986
    Ales

    Hi David,

    Thanks for your reply. This helps, but it’s still not exactly what I want to achieve.

    The problem is following:

    1) I have this basic category:
    https://dogfate.com/rescues/
    This category should look like this:
    https://www.animalfate.com/dog-breeders/
    This is possible with the approach you mentioned before.

    2) I have this sub-category:
    https://dogfate.com/rescues/golden-retriever/
    This category should look like this:
    https://www.animalfate.com/shih-tzu-breeders/
    Basically, it’s an article that links to other sub-pages, but I need to have this as a category, so the breadcrumbs are working properly:

    For this sub-category, I don’t want to show the latest posts.

    3) I have the final article:
    https://dogfate.com/7-golden-retriever-rescues-in-michigan/
    There is no need to change anything.

    Is this possible? The problem is the sub-category where I need to stop showing the latest posts.

    Elementor can do that, but I don’t want to use Elementor because it slows down the website. And I don’t want to use any redirects because that would mess the breadcrumbs.

    Thanks a lot!

    #1678395
    David
    Staff
    Customer Support

    How does Elementor all you to replace a Sub Category with a single post / static page?
    It may give me some other ideas.

    #1679011
    Ales

    Hi David,

    You go to Elementor templates in WP-Admin and add a new template as an archive:

    Then you design the page as you want with all the Elementor options available. You can select if you want to show the latest posts, archive title, but you can also fully customize it.

    When you hit publish, you have to select where you want to display this template, so you select “Categories,” and there, you can select any category or sub-category you wish.

    And the result is this: https://dogfate.com/rescues/golden-retriever/

    A fully custom page with no posts showed that is still a category (sub-category in this case).

    You can also check this final article: https://dogfate.com/11-golden-retriever-rescues-in-georgia/, where you can see in breadcrumbs that it works like a normal category.

    #1679135
    David
    Staff
    Customer Support

    So i assume you’re having to create a separate Elementor template for each of those ‘categories’ right ? As the category archive itself cannot be edited.

    In GP you would need to disable the Loop on the Category pages using this PHP Snippet:

    
    // Disable loop on category archives
    add_filter( 'generate_do_template_part', function( $do ) {
        if ( is_category() ) {
            return false;
        }
        return $do;
    } );

    Then you can use a Block Element and use a generate_before_main_content hook set to the display on the specific Category Archive.

    #1679353
    Ales

    Hi David,

    That’s correct. You need to create a template for each category page.

    Thanks for the PHP snippet. Is there any way how to use it only for some categories, for example by ID? I still want to show posts in some categories.

    Thanks!
    Alex

    #1679763
    Elvin
    Staff
    Customer Support

    Hi Ales,

    You can actually specify the category/categories within the if( is_category()) condition on the PHP snippet David provided.

    See codex reference here:
    https://developer.wordpress.org/reference/functions/is_category/#comment-498

    You can see different usage on the linked comment.

    #1694830
    Ales

    Hi,

    I finally had time to test this and I have 3 problems:

    1) When I use that PHP snippet that disables the loop on category archives, it also removes the Block Element where I have the content. This happens when I use generate_before_content as a hook, which I have to because when I use generate_before_main_content, it’s generated above the H1 (category name) and it’s not within the container with white background. Here is an example: https://dogfate.com/rescues/golden-retriever/

    I need to have my content generated under this H1 and inside the white container.

    2) Is there any way how I can change the H1 that shows on the category page so it’s different from what is the category name? Maybe here solution can be to just remove the original H1 and I will use my own in that Block Element. But still needs to solve the white container issue.

    3) When I look into the code, there are blank spaces inside the H1 tag, why is that, please?

    Thanks a lot!
    Alex

    #1695131
    Elvin
    Staff
    Customer Support

    1.) Ah yes that was actually the purpose of the code. The category specified within the condition means it won’t run the loop on that particular archive so it won’t interfere with your category archive page made from elementor.

    Unless we’ve misunderstood and that’s not what you’re trying to do? Let us know.

    2.) If you’re making the template from Elementor. All the things you’ll see will be whatever you set for the template.

    3.) Can you check the category label for any spaces? This particular element fetches whatever was placed within the Category Label field.

    #1695212
    Ales

    Hi Elvin,

    Thanks for your reply.

    Just for clarification, I decided to uninstall Elementor completely and use only GeneratePress and GenerateBlocks for this. Elementor is nice and does exactly what I need, but it’s also very slow.

    1) For example, this page: https://dogfate.com/rescues/golden-retriever/. I want to have the content in a white container under the H1, which is currently “Golden Retriever”. Right now, the content is above the H1, and it’s just on the grey background, not in a white container.

    2) I don’t use Elementor anymore. The thing is that when I use the H1 tag inside Block Element, there will be 2x H1 tags on that category page. One default, one from Block Element.

    3) There are no spaces. And it seems like this issue is also for other categories and on my other site.

    Thanks,
    Alex

    #1696093
    David
    Staff
    Customer Support

    In your Block Element try using the Hook: before_do_template_part
    Let us know if that works for you – and then we can look at the other things.

    #1696184
    Ales

    Hi David,

    Thanks a lot. It helped, but there are still 2 things. It looks like this: https://dogfate.com/rescues/golden-retriever/

    Problems:

    1) It’s not in the white container like all content is.
    2) The text is displayed multiple times, probably once for each post that should be in that category.

    Thanks!
    Ales

    #1696246
    David
    Staff
    Customer Support

    In that case – change the Hook to Custom Hook and in the field provided add: generate_after_loop
    You will have to add a Container Block as paren wrapper for your content to which you can add a background color and padding.

    #1696515
    Ales

    Hi David,

    Thanks a lot, this works!

    So, now the only thing I need to fix is that H1. Can I somehow have a different H1 than the category name? I can create an H1 heading in the category content, but the problem is that there is still the old one.

    I tried this CSS:

    .category .page-header {
        display: none;
    }

    And it looks exactly as I want (https://dogfate.com/rescues/golden-retriever/), but the original H1 (Golden Retriever) is only hidden, not removed, and I can’t have two H1 on the same page.

    Thanks!
    Ales

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