-
Hi there,
Is it possible to make the query loop loop through the categories and show the category title and maybe the description?
Best Regards,
Peter -
Fernando
Hi Peter,
No, it’s not possible. You need a custom code for that.
Where are you placing this? Is it just in a static page and do you want to query all categories?
-
Yes, just in a static plage.
-
Fernando
Try adding this snippet:
function category_list_shortcode() { // Get all categories $categories = get_categories(); // Output HTML for each category $output = '<ul>'; foreach ($categories as $category) { $output .= '<li>'; $output .= '<a href="' . esc_url(get_category_link($category->term_id)) . '">'; $output .= esc_html($category->name) . '</a>'; // Check if category has a description if (!empty($category->description)) { $output .= '<p>' . esc_html($category->description) . '</p>'; } $output .= '</li>'; } $output .= '</ul>'; return $output; } // Register the shortcode add_shortcode('category_list', 'category_list_shortcode');
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then, you can add a Shortcode Block to add this shortcode:
[category_list]
-
-
Fernando
You’re welcome!
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.