Archived topic
Dynamic Text List Of Terms showing only one term
3 replies · Started by Tim Taricco on November 24, 2022
I'm using the Dynamic Text List Of Terms in a Page Hero element type, and only one of the two terms of the taxonomy shows, although there are posts in both categories. This page https://dev4.mywebsiteserver.com/portfolio/ (PW: alittleaccent) shows the problem where only the "Commercial" category (https://dev4.mywebsiteserver.com/project-type/commercial/) is showing when there are posts in the "Residential" category (https://dev4.mywebsiteserver.com/project-type/residential/) too.
Hi Tim,
To clarify, are you opting to show all "Portfolio Types" on your Portfolio Archive page?
If so, using a GB Headline wouldn't work. It's only meant to be used for single posts, or individual posts in the Blog/Archive pages.
You'll need custom code to achieve this. Try adding this PHP snippet:
add_shortcode( 'insert_portfolio_types', function() {
ob_start();
// Start your PHP below
$cterms = get_terms( array(
'taxonomy' => 'portfolio_type'
) );
// var_dump($cterms);
if($cterms){
echo '<div class="custom-terms"><ul>';
foreach( $cterms as $cterm ) {
echo '<li class="custom-term"><a href="' . get_term_link( $cterm ) . '">' . $cterm->name . '</li>';
}
echo '</ul></div>';
}
// End your PHP above
return ob_get_clean();
} );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
This should give you a Shortcode - [insert_portfolio_types] that insert your Portfolio types. You can now add this Shortcode through a WordPress Shortcode Block.
We'll need custom CSS to fix how it looks afterward.
Thank you, Fernando, that solution works. You likely see my logic in thinking that the dynamic content in the Headline block should work. That should be a future update.
You're welcome Tim!
As for having such functionality in a future update, you may raise a feature request here: https://community.generateblocks.com/c/feature-requests/6