I am having issues with the get_the_terms php that is pulling in my current posts categories (custom taxonomy portfolio_category). I can successfully pull in the last category.
If you look at this page you’ll see links along the top: http://www.slarc.com/portfolio-view/central-control-building-east-texas/ those links are pulled in via get_the_ters_list but the links don’t have: www. slarc. com / projects in front of it. Where I need it to jump to a page with the same slug. That’s why I started working with the code below. It works, but it only pulls in ONE taxonomy? This is the second line of links on the page: http://www.slarc.com/portfolio-view/central-control-building-east-texas/
PHP Code:
ID, ‘portfolio_category’ );
if ( $terms && ! is_wp_error( $terms ) ) :
$portfolio = array();
foreach ( $terms as $term ) {
$portfolio[] = $term->name;
}
$portfolio_category = join( " | ", $portfolio );
?>
<h3 id="Proj_Categories"><ul>
<?php echo '<a href="http://www.slarc.com/projects/'.$term->slug.'">'.$term->name.'</a>'; ?>
</ul></h3>
<?php endif; ?>
How can I pull in all the taxonomies??
FYI-Ignore the links on top that show up. These are brough in with the get_the_terms_list
But those need the http:// www. slarc.com/ projects in front of the links.
Thanks,
Lorne
EDIT (GOT THE WORKING CODE Thanks jfacemyer!):
PHP Code:
ID, ‘portfolio_category’ );
if ( $terms && ! is_wp_error( $terms ) ) :
$portfolio = array();
foreach ( $terms as $term ) {
$portfolio[] = $term->name;
}
$portfolio_category = join( " | ", $portfolio );
?>
<h3 id='Proj_Categories'>
<?php
$url = site_url();
foreach ( $terms as $term ) {
$linklist .= "<li><a href='" . $url . "/projects/" . $term->slug . "'>" . $term->name . "</a></li>n";
}
echo "<ul>" . $linklist . "</ul>";
?>
</h3>
<?php endif; ?>
You need to include your html inside the foreach, something like this:
(I haven’t checked this code…)
It looks like you were trying to do something with making an array of the links, maybe, joined by pipes as separators? If so, make your array with the the terms, then do another foreach with that array and create the links.
Looks like you were only getting one of the terms because you were calling
$term
(not sure where that was set, outside of the first loop) rather than looping through the array of terms.You don’t need to build the URL, you can just get the term’s permalink like this:-