Site logo

[Resolved] Grid/gallery of category images for Blog Page

Home Forums Support [Resolved] Grid/gallery of category images for Blog Page

Home Forums Support Grid/gallery of category images for Blog Page

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1810886
    Fergal

    Hey there,

    I’m trying to do something similar to what was done here https://generatepress.com/forums/topic/grid-gallery-of-category-images/#post-1810852, but I want to display my top-level categories on my Blog page. I added images to categories using https://wordpress.org/plugins/categories-images/ and added the shortcode you typed out above to the “code snippets” plugin. I then tried to add the short code to the blog page using [category_grid id=”6″], but it isn’t working. Can you please tell me what I’m doing wrong or is there a better way to do this now?

    Thanks,
    Fergal

    #1811202
    David
    Staff
    Customer Support

    Hi there,

    couple of things:

    1. The shortcode doesn’t support arguments so it has to be: [category_grid]
    To limit it to the just the parent categories, you would edit Tom’s snippet and include the 'parent' => 0, arg ie.

    $args = array(
        'orderby' => 'name',
        'order' => 'ASC',
        'hide_empty' => 1,
        'parent' => 0,
    );

    2. How are you adding the shortcode to the Blog Page ? As it would need to be hooked in.

    #1811606
    Fergal

    Hey David,

    I made the adjustments you mentioned in 1.

    2. Clearly I have a lot to learn about shortcodes and hooks as I was trying to just insert the shortcode into the blog page via Gutenberg. Now, I created a hook element where hook is “generate_before_main_content” and display location is “Blog”. Then checked the execute shortcodes box and inserted [category_grid] into the editor. It works like a charm.

    Thanks so much!
    Fergal

    #1812073
    David
    Staff
    Customer Support

    Glad to be of help 🙂

    #1813915
    Fergal

    Hey David,

    Can we please modify the php to only show this category grid on the first page of the blog page?

    I don’t want the category grid showing up on /blog/page/2, /blog/page/3, etc. only on /blog/.

    Thanks,
    Fergal

    #1814150
    Elvin
    Staff
    Customer Support

    Hi Fergal,

    I don’t think that’s doable in PHP without breaking the pagination linking. The navigation would break because the links won’t work (all will point to /blog).

    If you simply want to display /blog on the address bar of the browser, you can do that with JS but that customization is out of our scope.

    #1816796
    Fergal

    Hey Elvin,

    I think there was some confusion as to what I was looking for. I was able to find a condition that worked for this task:
    if ( !is_paged())

    and now the categories only show up on the first page of the blog posts page.

    Regards,
    Fergal

    #1816817
    Elvin
    Staff
    Customer Support

    Nice one. Glad you got it sorted. Thanks for letting us know. 🙂

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