- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by David.
-
AuthorPosts
-
December 22, 2020 at 1:59 pm #1591237Edmond
Hi all,
Any idea how to create a categories list like this fast: https://www.trustpilot.com/categories ?
I have Generatepress premium and also Elementor Pro, so I can use both. From what I tried I found no simple way to create something like that, so maybe I am missing something.
December 22, 2020 at 5:42 pm #1591386ElvinStaffCustomer SupportHi,
I believe elementor, even the pro version doesn’t have a particular category widget that lets you customize what displays. You’ll have to get a Elementor add-on for this.
One way of doing this is to manually place links for every category and its own subcategory. But this will surely be tedious depending on how many are existing.
Another way is to make your own shortcode for this.
December 23, 2020 at 2:39 am #1591723EdmondHello,
Since i’m building a directory listing website that’s going to be somewhat tedious. I thought perhaps there’s something on GP/Elementor to help with that.
Thanks anyway!
December 23, 2020 at 3:54 am #1591808DavidStaffCustomer SupportHi there,
we could create a shortcode function to output a list of the Categories, each with a nested list of its posts.
1. Add this PHP Snippet to your Site:
function db_get_category_posts() { $args = array( 'posts_per_page' => -1 ); $query = new WP_Query($args); $q = array(); while ( $query->have_posts() ) { $query->the_post(); $a = '<a href="'. get_permalink() .'">' . get_the_title() .'</a>'; $categories = get_the_category(); foreach ( $categories as $key=>$category ) { $b = '<a href="' . get_category_link( $category ) . '">' . $category->name . '</a>'; } $q[$b][] = $a; // Create an array with the category names and post titles } /* Restore original Post Data */ wp_reset_postdata(); $html = ''; foreach ($q as $key=>$values) { $html .= '<div class="cateogory-list">' . $key; $html .= '<ul>'; foreach ($values as $value){ $html .= '<li class="cat-post-link">' . $value . '</li>'; } $html .= '</ul></div>'; } return $html; } add_shortcode( 'category_posts', 'db_get_category_posts' );
2. Add the
[category_posts]
shortcode to the page you want it displayed.December 23, 2020 at 6:07 am #1591904EdmondWow, thanks a lot i will try that.
December 23, 2020 at 6:15 am #1591914DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.