Before you ask please READ THIS

Showing taxonomy list beside work title on works list (work-list.php)

edited February 2014 in Beach Please Posts: 23

Hello,

I'd like to show a list of taxonomies and subtaxonomies inside the span containing the title and subtitle of each workon works-list.php

I've installed a Types plugin to create custom post types and taxonomies in order to add more taxonomies to the one attached to Work Item called Genre.

I've created a new function (function custom_taxonomies_terms_links_home) added to functions.php on child theme as shown that outputs all taxonomies and subtaxonomies:

// get taxonomies terms links
function custom_taxonomies_terms_links_home(){
  // get post by post id
  $post = get_post( $post->ID );

  // get post type by post
  $post_type = $post->post_type;

  // get post type taxonomies
  $taxonomies = get_object_taxonomies( $post_type, 'objects' );

  $out = array();
  foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){

    // get the terms related to post
    $terms = get_the_terms( $post->ID, $taxonomy_slug );

    if ( !empty( $terms ) ) {
        $out[] = "<div class='taxo-total'>";
        $out[] = "<div class='taxo'>" . $taxonomy->label . ":</div>\n";
        foreach ( $terms as $term ) {
            $out[] = '<div class="subtaxo"><a href="' . get_term_link( $term->slug, $taxonomy_slug ) . '">' .    $term->name . "</a></div>\n";
      }
      $out[] = "</div>";

    }
  }

  return implode('', $out );
}

I'd like to show the result of this function (list of taxonomies) inside the span containing the title ('get_the_title') and subtitle (a13_subtitle) on each item of Works list (works-list.php).

Maybe like this:

echo '<em class="cov"><span>' . a13_subtitle('small') . get_the_title() . custom_taxonomies_terms_links_home() . '</span></em>';

It breaks the work list and only shows first work's list, and wrongly.

I've done this before on Single Work template (single-work.php) successfully.

May be a problem of global/local variables?

Post edited by selvaperux on

Comments

  • AirAir
    Posts: 10,970
    There is a custom query in works list, so maybe in your function instead of $post->ID use get_the_ID().

    However you have to debug inside your function what are variables. Use for example var_dump() to check what variable has what value during loop of works list.

    Good luck!

    With regards.
  • thank you very much!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!