Wordpress - Custom taxonomy page of custom post type listing by terms


Wordpress - Custom taxonomy page of custom post type listing by terms



I have a taxonomy-taxonomy.php page that needs to look like so:

CUSTOM POST TYPE TITLE (RESOURCES)

Custom Taxonomy 1 (Resource Types)

Resource Type Term 1 (White Papers)

  • White Paper post 1

    White Paper post 2

    White Paper post 3

Resource Type Term 2 (Videos)

  • Videos post 1

    Videos post 2

    Videos post 3

Tried to make sense of all the new documentation for Wordpress 3.0, but it only made me more confused as it seems to be mixed up with 2.8.


Wordpress: Display Total Number of Posts For Current Month, Week and Day?

1:

WordPress Visual Editor - Indent Button and Unordered Lists
It's not necessary to transform the object to an array, you must perfectly job with the object without too enough hassle. Google custom search results page don't show any resultsWhat is curious (at least for me), is this you receive any thing like this:. What is the correct way to setup “Pretty” permalinks in Wordpress 3.0
  Array   (       [0] => stdClass Object           (               [term_id] => 7               [name] => Magister comunicaciones aplicadas               [slug] => magister-comunicaciones-aplicadas               [term_group] => 0               [term_taxonomy_id] => 7               [taxonomy] => linea-de-estudio               [description] =>                [parent] => 0               [count] => 4           )        [1] => stdClass Object           (                [term_id] => 8                [name] => Engagement marketing                [slug] => engagement-marketing                [term_group] => 0                [term_taxonomy_id] => 8                [taxonomy] => linea-de-estudio                [description] =>                 [parent] => 0                [count] => 5           )   ) 
It's basically, an array of objects, so you've to treat them this way. Get this code I made to also do month/day/week post count? WordpressFor case if I want the name of the the first one:. what the best solution for user driven content on my website
$myterms = receive _terms('taxonomy-name', 'orderby=none&hide_empty');     echo  $myterms[0]->name; 
If you need to iterate through the elements, you still must use foreach();.. Iterate through custom post type by custom taxonomy type? (Ordering wordpress posts by category, or displaying custom post type by taxonomy term)
foreach ($myterms as $term) { ?>     <li><a href="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li> <?php } ?> 
That way you must post the articles from your taxonomy.. Dissallow robots for a while For the custom post types, you'll have to create a loop like this:.
$args = array(     'post_type' => 'post-type-name',     'taxonomy' => 'term'     //for case     //'resources' => 'videos' );  //  assigning variables to the loop global $wp_query; $wp_query = new WP_Query($args);  // starting loop while ($wp_query->have_posts()) : $wp_query->the_post();  the_title(); blabla....  endwhile; 
Then you must create multiple loops each of one for each taxonomy/term :).. If you want to receive even more fancy (don't want to repeat yourself a hundred times) you must include the second loop inside the first one and assign variables to the taxonomy (resources ie) and the terms it has (videos) (from your case only the last one). The idea is this you would have a normal (typical) wordpress loop restricted to the custom post-type and each one of the terms..
foreach ($myterms as $term) : ?>     <li><a href="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li> <?php          $term_name = $term->slug;          $args = array(         'post_type' => 'post-type-name',         'taxonomy' => "$term_name"         );     //  assigning variables to the loop    global $wp_query;    $wp_query = new WP_Query($args);     // starting loop posting only    while ($wp_query->have_posts()) : $wp_query->the_post();     the_title();    blabla....     endwhile;  endforeach; ?> 
Obviously you must did the inverse thing too, create the normal loop for a single-template custom type (it's looks like you have only one), and inside includes all the custom terms.. Not very elegant, although that's the best way I must came up with it :P. Hope this any one must understand this, sounds confusing. . Maybe could it be possible with any callback function?..

2:

Hey manon1165 , I actually just accomplished this. Was a huge pain, hopefully my code snippet will help!. I made a custom page template. And did any thing along the lines of.
<?php $categories = receive _terms('taxonomy-name', 'orderby=name&hide_empty=0'); $cats = object_to_array($categories); ?> 
Now, just print_r($cats) and you will see the array of the categories.. You will need to convert the object to an array, I did so with..
function object_to_array($data)  {   if(is_array($data) || is_object($data))   {     $result = array();      foreach($data as $key => $value)     {        $result[$key] = object_to_array($value);      }     return $result;   }   return $data; } 
I did.
<ul id="cat-list"> <?php foreach($cats as $cat) { ?>   <li><a href="/taxonomy-name/<?php echo $cat['slug']; ?>"><?php echo $cat['name']; ?> (<?php echo $cat['count']; ?>)</a><br><?php echo $cat['description']; ?></li> <?php } ?> </ul> 
Hope this helps!.


63 out of 100 based on 48 user ratings 723 reviews