Archived topic
Create wp_list_categories block in mysite.com/blog and all Archive Blog
7 replies · Started by Trần on August 8, 2021
I have a question maybe relate with this post:
How can I creat a category of Archive for my website https://kimquy.com.vn/blog/ like that webste: https://www.ultimatebeaver.com/modules/advanced-posts/example-4/
It displays some category of blog with a beautifull style
All Creative Fashion Outdoor Portraits
I don’t need to custom display for blogs in Archive Blog.
I need add a category for Archive Pages: List of all category blog.
How can I do?
Hi there,
to clarify: You're trying to make a page that lists posts with interactive button filters?
If so, I'm afraid GP doesn't have this feature.
You'll need a third-party plugin to run something like this on your site. :D
Or if you're familiar w/ scripting, consider implementing filterizr.
https://yiotis.net/filterizr/#/
I just only want to use anchor instest of interactive button filters. How can I do?
Did you mean these buttons but without the dynamically changing post list? https://share.getcloudapp.com/6quYWrEW
So basically just pure wp_list_categories()?
We can turn that into a shortcode.
Example:
function getCategoryList()
{
echo"<ul>";
wp_list_categories('orderby=name&show_count=1&title_li=');
echo"</ul>";
}
add_shortcode('mycatelist', 'getCategoryList');
You then use the shortcode [mycatelist] using the shortcode block. You may have to manually style the list though.
Here's a good article about it - https://www.codexpedia.com/wordpress/how-to-create-shortcode-in-wordpress/
Thank you for your support.
I used other solution (use Elements in GP Premium):
<?php
$categories = get_categories();
foreach($categories as $category) {
echo '<a class="read-more button" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a> ';
}
?>
And Display rules: Blog and all Archive. But I found, my shop (woocommerce and category in woocommerce is affected too)
So I add a litle check:
<?php
if(get_post_type()=='post'){
$categories = get_categories();
foreach($categories as $category) {
echo '<a class="read-more button" href="' . get_category_link($category->term_id) . '">' . $category->name . '</a> ';
}
}
?>
It works quite well on mobile and desktop.
https://kimquy.com.vn/blog/
Ah yes that should work as well.
And that may be better actually. Because you can change the tags used and customize attributes better.
Thanks for sharing it with us.
And can use the inheritance class of GeneratePress: read-more button.
Hope it can help some one!
Thanks!
No problem. :D