- This topic has 7 replies, 3 voices, and was last updated 4 years, 10 months ago by
Elvin.
-
AuthorPosts
-
June 4, 2021 at 9:12 pm #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,
FergalJune 5, 2021 at 7:43 am #1811202David
StaffCustomer SupportHi 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.
June 5, 2021 at 11:20 am #1811606Fergal
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!
FergalJune 6, 2021 at 4:20 am #1812073David
StaffCustomer SupportGlad to be of help 🙂
June 7, 2021 at 12:58 pm #1813915Fergal
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,
FergalJune 7, 2021 at 6:16 pm #1814150Elvin
StaffCustomer SupportHi 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.
June 9, 2021 at 5:18 pm #1816796Fergal
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,
FergalJune 9, 2021 at 5:57 pm #1816817Elvin
StaffCustomer SupportNice one. Glad you got it sorted. Thanks for letting us know. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.