Skip Navigation

[Resolved] Custom taxonomy template with php

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by aitorS 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1965701

I have created a custom template to show the custom taxonomies "taxonomy.php" I want to show in this template a list with all the posts of each taxonomy but I am not sure how to do it.

#1965885

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for getting in touch.

For clarity if you have a Taxonomy A, you want to show all the posts under this taxonomy A regardless of post type ?

If not can you provide a little more clarity on the issue so I know exactly what you are referring to.

Thanks,
Shane

#1966847

I want to show all the entries of Taxonomy A within the Taxonomy template, without having to make a template for each Taxonomy

#1966899

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Aitor,

I did some checks on this and you won't be able to do it with the taxonomy.php file at least not without some extensive custom coding.

However a workaround to this is that you can create a custom page with the exact same name and slug as your taxonomy's root directory. So lets say you have a taxonomy called Event Type with the slug event-type, then I will create a page called Event Type and ensure that the slug is the same event-type.

Then I would go to Toolset -> Views and create a taxonomy view there. If you are not seeing this option you will need to enable the classic views editor by going to Toolset->Settings and scroll to Editing Experience and select "Show both the legacy and Blocks interface and let me choose which to use for each item I build".

Once you've refreshed the page you should be presented with the option to use the classic views. Next you will need to create the taxonomy view and then populate it with the taxonomy information using the Loop Wizard.

Finally just add this taxonomy view to the page that you've created and anytime you go to the root slug of your taxonomy it will display this page with your taxonomy view that will list out your terms.

Please let me know if this helps or if you need further clarification.

Thanks,
Shane

#1970261

Finally I found a solution for this issue, I collect the final part of the URL that matches the term of the taxonomy, then I pass this variable into a WP Query that shows me the taxonomy, I copy here the code that does everything in case it works for you for the future.

$url = $_SERVER["REQUEST_URI"];
$taxonomia = basename($url);
function show_tax() {
		  $html = "";
		  $url = $_SERVER["REQUEST_URI"];
		$taxonomia = basename($url);
		  $my_query = new WP_Query( array(
		       'post_type' => array('cursos_udeka','oposiciones_udeka'),
		       'tax_query' => array(
			        array (
			            'taxonomy' => 'especialidad-curso',
			            'field' => 'slug',
			            'terms' => $taxonomia
			        )
			    ),
			   'order' => 'DESC'
		  ));
		  if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
		  		$post_type = get_post_type( get_the_ID() );
				$html .= '<div class="taxonomy-post">';
		  		$html .= '<div class="img-tax-post"><a href="' . get_permalink() . '"><img src="'.get_the_post_thumbnail_url().'" alt="'.get_the_title().'"></a><div class="fusion-clearfix"></div></div>';
		  		$html .= '<div class="title"><h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3></div>';
		    	$html .= '<div class="fusion-clearfix"></div></div>';
		  endwhile; endif;
		  $html .= '<div class="fusion-clearfix"></div>';
		  return $html;
}