-
bennyuk2
Is there any date that we can use a post navigation element in GP2 that can show links within the same term (like it does in GP1)?
I can see the old templates make it possible, using the old GP1 method, just not using GP2 method.
Thanks
Ben -
Hi there,
You can use GB v2 to create post navigation element.
For next post use
{{post_title source:next-post}}
for text, and{{post_permalink source:next-post}}
for link.For previous post use
{{post_title source:previous-post}}
for text, and{{post_permalink source:previous-post}}
for link.Here’s an example can be pasted to your block element:
<!-- wp:generateblocks/element {"uniqueId":"125fe0d3","tagName":"div","styles":{"display":"flex","flexDirection":"column","alignItems":"flex-start","flexGrow":"1","flexShrink":"1","flexBasis":"0px"},"css":".gb-element-125fe0d3{align-items:flex-start;display:flex;flex-basis:0px;flex-direction:column;flex-grow:1;flex-shrink:1}"} --> <div class="gb-element-125fe0d3"><!-- wp:generateblocks/text {"uniqueId":"5d4b34be","tagName":"a","styles":{"display":"inline-flex","alignItems":"center","columnGap":"0.5em","fontSize":"12px","marginBottom":"10px",".gb-shape svg":{"width":"1em","height":"1em","fill":"var(\u002d\u002dbase-3)"},"textDecoration":"none"},"css":".gb-text-5d4b34be{align-items:center;column-gap:0.5em;display:inline-flex;font-size:12px;margin-bottom:10px;text-decoration:none}.gb-text-5d4b34be .gb-shape svg{width:1em;height:1em;fill:var(\u002d\u002dbase-3)}","htmlAttributes":{"href":"{{post_permalink source:previous-post}}"},"metadata":{}} --> <a class="gb-text-5d4b34be" href="{{post_permalink source:previous-post}}"><span class="gb-shape"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.2 288 416 288c17.7 0 32-14.3 32-32s-14.3-32-32-32l-306.7 0L214.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"></path></svg></span><span class="gb-text">PREVIOUS</span></a> <!-- /wp:generateblocks/text --> <!-- wp:generateblocks/text {"uniqueId":"ada67ae6","tagName":"a","styles":{"display":"inline-flex","alignItems":"center","columnGap":"0.5em","fontSize":"20px","marginBottom":"10px",".gb-shape svg":{"width":"1em","height":"1em","fill":"var(\u002d\u002dbase-3)"},"textDecoration":"none"},"css":".gb-text-ada67ae6{align-items:center;column-gap:0.5em;display:inline-flex;font-size:20px;margin-bottom:10px;text-decoration:none}.gb-text-ada67ae6 .gb-shape svg{width:1em;height:1em;fill:var(\u002d\u002dbase-3)}","htmlAttributes":{"href":"{{post_permalink source:previous-post}}"},"metadata":{},"className":"hide-on-mobile"} --> <a class="gb-text gb-text-ada67ae6 hide-on-mobile" href="{{post_permalink source:previous-post}}">{{post_title source:previous-post}}</a> <!-- /wp:generateblocks/text --></div> <!-- /wp:generateblocks/element -->
-
bennyuk2
thanks but there is no option to show ONLY posts within the same term (same category), as there was in v1 post nav element.
Will this be added?
-
Yes, you are right, the option is gone.
I’ll check if the option will be added back in the future.
-
So we reviewed the issue and think it’s nessasaery, I’ve raised a feature request, hopefully it will be added in the future update.
For now, use below code to generate 4 new dynamic tags
– Previous Post Title – same term
– Previous Post URL – same term
– Next Post Title – same term
– Next Post URL – same termadd_action('init', function () { if (! class_exists('GenerateBlocks_Register_Dynamic_Tag')) { return; } // Previous Post Title new GenerateBlocks_Register_Dynamic_Tag([ 'title' => __('Previous Post Title - same term', 'generateblocks'), 'tag' => 'previous_post_title_same_term', 'type' => 'post', 'supports' => [], 'description' => __('Displays the previous post title of the current post, in the same term.', 'generateblocks'), 'return' => function () { $prev_post = get_adjacent_post(true, '', true); return $prev_post ? esc_html(get_the_title($prev_post->ID)) : ''; } ]); // Next Post Title new GenerateBlocks_Register_Dynamic_Tag([ 'title' => __('Next Post Title - same term', 'generateblocks'), 'tag' => 'next_post_title_same_term', 'type' => 'post', 'supports' => [], 'description' => __('Displays the next post title of the current post, in the same term.', 'generateblocks'), 'return' => function () { $next_post = get_adjacent_post(true, '', false); return $next_post ? esc_html(get_the_title($next_post->ID)) : ''; } ]); // Previous Post URL new GenerateBlocks_Register_Dynamic_Tag([ 'title' => __('Previous Post URL - same term', 'generateblocks'), 'tag' => 'previous_post_url_same_term', 'type' => 'post', 'supports' => [], 'description' => __('Displays the previous post URL of the current post, in the same term.', 'generateblocks'), 'return' => function () { $prev_post = get_adjacent_post(true, '', true); return $prev_post ? get_permalink($prev_post->ID) : ''; } ]); // Next Post URL new GenerateBlocks_Register_Dynamic_Tag([ 'title' => __('Next Post URL - same term', 'generateblocks'), 'tag' => 'next_post_url_same_term', 'type' => 'post', 'supports' => [], 'description' => __('Displays the next post URL of the current post, in the same term.', 'generateblocks'), 'return' => function () { $next_post = get_adjacent_post(true, '', false); return $next_post ? get_permalink($next_post->ID) : ''; } ]); });
-
bennyuk2
thanks for the update, hopefully feature will be added back soon.
-
No Problem 🙂
- You must be logged in to reply to this topic.