- This topic has 15 replies, 2 voices, and was last updated 6 months, 4 weeks ago by
David.
-
AuthorPosts
-
August 24, 2022 at 1:43 am #2322071
Sebastian
Hey guys
I’m trying to insert links to a custom taxonomy by using the dynamic text block function, to use as a menu in my footer (element site footer). Problem is, it’s only showing up when I’m on the actual archive page. I’ve tried both “list of terms” as well as “term meta”. None is working as I want it to. Is this even possible?
Big thanks
August 24, 2022 at 3:03 am #2322144David
StaffCustomer SupportHi there,
just to be clear, are you wanting a footer menu that is a list of all your custom taxonomy terms ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 4:04 am #2322200Sebastian
Well actually I would like to know how to do both. I would like to insert a menu concisting of links to my custom categories, styled in the same way as my other links in the columns next to it.
And I would also like to know how to insert single links (one per line) pointing to the same thing.
In both cases preferably using the block editor dynamic field.
August 24, 2022 at 6:17 am #2322296David
StaffCustomer SupportGP and GB Dynamic data both require a content source and to be inside the loop.
So you can use them to display the tax terms for current post.
But they cannot be used ( today ) to list ALL terms from a specific taxonomy.You could create a shortcode to display them with this PHP Snippet:
add_shortcode( 'custom_tax', function(){ $tax_args = array( 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => true, ); $tax_terms = get_terms( 'category', $tax_args ); $html = ''; if ( ! empty( $tax_terms ) ) { $html = '<ul class="tax-cat-nav">'; foreach ( $tax_terms as $key => $term ) { $html .= sprintf( '<li> <a href="%1$s"> %2$s </a> </li>', get_term_link( $term ), $term->name ); } $html .= '</ul>'; } return $html; });
In this line:
$tax_terms = get_terms( 'category', $tax_args );
change thecategory
to your taxonomy name.
And then display the list using[custom_tax]
shortcode.It will need some CSS to style it – and i can help with that if you require.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 6:48 am #2322338Sebastian
Hi
I changed
$tax_terms = get_terms( 'category', $tax_args );
to$tax_terms = get_terms( 'agent_types', $tax_args );
but still only [custom_tax] showing up on the frontend?When I’m on the admin screen for my categories I have the following up in the address bar:
/wp-admin/edit-tags.php?taxonomy=agent_types&post_type=agent
. Don’t I somehow have to add what post_type I’m referring to in the params?August 24, 2022 at 6:53 am #2322342David
StaffCustomer SupportWhere did you add the
[custom_tax]
shortcode ? Does it work if you add it in the post/page content ?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 6:56 am #2322346Sebastian
I put it inside the site footer (elements). Same thing if I put right in the main content (with block editor).
August 24, 2022 at 7:11 am #2322358David
StaffCustomer SupportIf its showing
[custom_tax]
then it means that the shortcode is not being recongised.
When you added it to the post content did you use a Shortcode block ?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 7:12 am #2322360Sebastian
Yes!
August 24, 2022 at 7:39 am #2322376David
StaffCustomer SupportThere is no
post_type
arg for theget_terms
function.
The above code should show ALL the terms in the custom taxonomy even if it was attached to many post types.How was the snippet added to your site ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 7:44 am #2322379Sebastian
You’re right, I’m very sorry but I didn’t want to type the actual code in the open forum and I totally forgot to mention this in the Private info area. If it’s ok I’ll give you the details this time.
August 24, 2022 at 9:24 am #2322623David
StaffCustomer SupportMy issue is:
If the PHP Snippet here is added correctly then you will see either:
a. A list of terms
OR
b. Nothing as the shortcode will return the empty $html.
If you changed the
$tax_terms = get_terms( 'agent_types', $tax_args );
and the Custom Taxonomy is not recognised then it will most probably generate an Error.As that is not happening then it means WordPress does not recognise the
[custom_tax]
shortcode or it is not allowing shortcodes.To test can you add this snippet to your site:
add_shortcode( 'hello_shortcode', function() { return '<p>Hello this shortcode works</p>'; });
Then add the
[hello_shortcode]
to your site.
This should display that simple message – does that work ?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 11:32 pm #2323129Sebastian
I already have some custom shortcodes working on the site, so it didn’t make no sense.
After some digging I finally found the culprit. For some reason the[...]
around the shortcode had been stripped on insertion. I manually typed them back in and voilà, now it’s working.August 25, 2022 at 3:12 am #2323292David
StaffCustomer SupportGlad to hear that!
Do you need any assistance with CSS to style the list ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 25, 2022 at 3:44 am #2323320Sebastian
I’m periodically helplessly lost when it comes to code. CSS however is right up my alley 😉 Thank you David!
-
AuthorPosts
- You must be logged in to reply to this topic.