- This topic has 9 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
February 7, 2023 at 12:37 pm #2525030
Robert
I am trying to make a glossary just like this one:
https://ahrefs.com/seo/glossary
What’s the best way or the recommended way to do this with generatepress?
February 7, 2023 at 1:03 pm #2525059Ying
StaffCustomer SupportHi Robert,
You can use GenerateBlocks’s Query loop block to output a certain category of posts.
The homepage would be a static page, then you can add Query loop blocks by category.
February 7, 2023 at 1:27 pm #2525083Robert
So, I’d need to make every individual page manually, and then I can link them all up on a /glossary page using a Query loop?
February 7, 2023 at 1:49 pm #2525107Ying
StaffCustomer SupportI’d need to make every individual page manually
Do you mean a page like this one? https://ahrefs.com/seo/glossary/10x-content
If so, you can create a
block element - content templateto assign a certain layout for all those individual pages, then in the page editor, you only need to add the actual content.https://docs.generatepress.com/article/block-element-content-template/
February 8, 2023 at 1:20 pm #2526419Robert
Okay, so I would 1) make the block element content template, 2) create the individual pages for each entry and apply the block element content template to those pages, and 3) link them all up on a /glossary page using a Query loop?
Is that right? Anything else?
February 8, 2023 at 5:55 pm #2526593Ying
StaffCustomer SupportThat is correct 🙂
February 9, 2023 at 3:48 am #2527002Robert
Is there a way to sort the pages alphabetically using the query loop?
February 9, 2023 at 4:39 am #2527064David
StaffCustomer SupportHi there,
select the Query Loop block, and in Parameters Add 2 x new Parameters:
1. Order:
ASC
2. Order by:TitleFebruary 9, 2023 at 4:46 am #2527069Robert
Will that enable me to create sections for each glossary term, where each section is a letter? For example, A, B, C, etc.
February 9, 2023 at 8:27 am #2527406David
StaffCustomer SupportAah, ok.
Thats a lot more tricky, and for now i would not use a Query Loop for that.
Instead you can create your own custom loop shortcode with this PHP Snippet:function post_glossary() { global $post; // Set query args $args = array( 'post_type' => 'post', 'posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC', 'ignore_sticky_posts' => 1 ); $glossary = new WP_Query($args); // Output loop if ( $glossary->have_posts() ) { ob_start(); $curr_letter = ''; echo '<div class="post-glossary">'; while ($glossary->have_posts()) : $glossary->the_post(); $title = get_the_title(); $this_letter = $title[0]; if ( $this_letter != $curr_letter ) { if ( '' != $curr_letter ) { echo'</div></section>'; } echo '<section>'; echo '<h2 class="section-title">' . $this_letter . '</h2>'; echo '<div class="posts-wrapper">'; } $curr_letter = $this_letter; do_action('db_glossary_content'); endwhile; wp_reset_postdata(); return ob_get_clean(); } } add_shortcode('glossary', 'post_glossary');Then on your glossary page, add
[glossary]This will create the Loop, that will create a section for each letter, and inside that loop is a custom hook:
db_glossary_contentwhich we can use to display each post.Now create a Block Element – Content Template
Add your content template, for displaying the title, exerpt etc.
But change the Element Type from Content Template toHook.
Set the Hook toCustom, and in the field provided add:db_glossary_content
Set the Display Rules to Entire Site -
AuthorPosts
- You must be logged in to reply to this topic.