0
votes

On a custom post type archive I'm trying to add the custom taxonomy terms slug as a css class to the tag. I've managed to get it to output the page->ID but struggling to get the $term->slug to work. Feel like I'm missing something really simple. Here's the full code, thanks for any help:

     <?php

$parent_pages = get_pages( array( 'parent' => 0, 'post_type'=> 'archive', 'orderby' => 'menu_order' , 'order' => 'ASC', 'sort_column' => 'menu_order' ) );
foreach ( $parent_pages as $parent_page ) {


echo '<h1 class="page-heading" id="';
echo $parent_page->post_name;
echo '">';

echo $parent_page->post_title;
echo '</h1>';
 echo '<div class="wrapper grid4">';

$all_pages = get_pages(array( 'post_type'=> 'archive',  'orderby' => 'menu_order' , 'order' => 'ASC', 'sort_column' => 'menu_order' ) );
$child_pages = get_page_children($parent_page->ID, $all_pages );
foreach ( $child_pages as $child_page ) {
  echo '<article class="post col ' . $child_page->ID, $term->slug .'">';

 echo '<a class="fancybox" data-fancybox-type="iframe" href="http://www.iofpi.co.uk/civicworks.net/wp-content/plugins/pdfjs-viewer-shortcode/web/viewer.php?file=http://www.iofpi.co.uk/civicworks.net/wp-content/uploads/2014/05/Citizen_Manchester.pdf" title="' . the_title_attribute('echo=0') . '" >';

  echo get_the_post_thumbnail( $child_page->ID, 'medium');

  echo '</a>';


    echo '<h1>';
  echo $child_page->post_title;
  echo '</h1>';
  echo '</article>';
}
     echo '</div>';
  }
  ?>
1
from where are you getting value of "$term->slug" ? - Arka
Not sure I understand, I've added some custom taxonomy and thought I could just use $term->slug to output the taxonomy. How would I get them? - leanda
before foreach use below code see whole object. echo "<pre>"; print_r($child_pages); echo "</pre>"; die(); - Arka
Refer this link - Arka

1 Answers

0
votes

Use this function get_the_terms( $id, $taxonomy ) just pass it the post id in your case '$parent_page->ID' and the Name of taxonomy to retrieve terms from. For example: 'category', 'post_tag', 'taxonomy slug'

It will return an object and you can then access the slug with, say $result->slug.