Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've put some thought into this but Can't really figure out what direction I take in getting rid of certain terms in my testimonial_category called 'home', 'homeone', hometwo. I only want to stop these displaying in a link format on the relevant page.

Here is the code the process's all the terms within testimonial_category, I was thinking I need to somehow add a filter that stops these 3 named terms appearing as links but could really do with some advice on how to do this.

<div id="main" class="floatleft">

    <div class="case-study"> 
        <h1 class="p-title">Testimonials</h1>
        <div class="breadcrumb"> 
            <ul class="filter group">
                <li class="all current"><a href="#">All<span></span></a></li>
                <?php
                $terms = get_terms("testimonial_category");
                $count = count($terms);
                if ($count > 0) {
                    foreach ($terms as $term) {
                        ?><li class="<?php echo $term->slug; ?>"><a href="#"><?php echo $term->name; ?><span></span></a></li><?php
                    }
                }
                ?>
            </ul>
        </div>
        <div class="clear"></div>

Many thanks for any help.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The function get_terms has a convenient $args parameter which allows you to customize your query to meet your needs; in your case, it would be something as simple as:

$args = array(
    'exclude'       => array(1,2,3)
);

$terms = get_terms("testimonial_category", $args);

The array to exclude must contain the category ids of the categories you wish to leave out.

share|improve this answer
    
I'll try this solution, didn't even know you could exclude array id's like that. –  dannyw24 Jul 8 '13 at 15:39
    
You can check the link provided to see all the available options. –  Sunyatasattva Jul 8 '13 at 15:40
    
Thanks, I've learn't that now seems a very easy solution –  dannyw24 Jul 8 '13 at 15:45

This is a bit of a hack... (hardcoding variables like this isn't best practice, IMO) but it's good example to get your wheels turning...

<?php
//...
foreach ($terms as $term):?>

    <?php /*If the term name is anything but not 'home' or 'homeone' then echo the list item */ ?>
    <?php if($term->name != 'home' || $term->name != 'homeone' ):?>

        <li class="<?php echo $term->slug; ?>">
            <a href="#"><?php echo $term->name; ?><span></span></a>
        </li>

    <?php endif; ?>
<?php endforeach; ?>
share|improve this answer
1  
Although I could see this working, I think the other solution is neater. –  dannyw24 Jul 8 '13 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.