0

i created filterable portfolio using this tutorial

http://wp.tutsplus.com/tutorials/creating-a-filterable-portfolio-with-wordpress-and-jquery/

everything working well , but it grab the sub tags and its post also not only the main tags . how i can stop this issue ?

        <?php
             $terms = get_terms("tagportifolio");
             $count = count($terms);
             echo '<ul id="portfolio-filter">';
                echo '<li><a href="#all" title="">All</a></li>';
             if ( $count > 0 ){

                    foreach ( $terms as $term ) {

                        $termname = strtolower($term->name);
                        $termname = str_replace(' ', '-', $termname);
                        echo '<li><a href="#'.$termname.'" title="" rel="'.$termname.'">'.$term->name.'</a></li>';
                    }
             }
             echo "</ul>";
        ?>
        <?php 
            $loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1));
            $count =0;
        ?>

        <div id="portfolio-wrapper">
            <ul id="portfolio-list">

            <?php if ( $loop ) : 

                while ( $loop->have_posts() ) : $loop->the_post(); ?>

                    <?php
                    $terms = get_the_terms( $post->ID, 'tagportifolio' );

                    if ( $terms && ! is_wp_error( $terms ) ) : 
                        $links = array();

                        foreach ( $terms as $term ) 
                        {
                            $links[] = $term->name;
                        }
                        $links = str_replace(' ', '-', $links); 
                        $tax = join( " ", $links );     
                    else :  
                        $tax = '';  
                    endif;
                    ?>

                    <?php $infos = get_post_custom_values('_url'); ?>

                    <li class="portfolio-item <?php echo strtolower($tax); ?> all">
                        <div class="thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( array(215, 215) ); ?></a></div>
                        <div class="projectcontent">
                        <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                        <p class="excerpt"><a href="<?php the_permalink() ?>"><?php echo get_the_excerpt(); ?></a></p>
                        <p class="links"><a href="<?php the_permalink() ?>">More Details &rarr;</a></p>

                        </div>
                    </li>

                <?php endwhile; else: ?>

                <li class="error-not-found">Sorry, no portfolio entries for while.</li>

            <?php endif; ?>


            </ul>

            <div class="clearboth"></div>

        </div> <!-- end #portfolio-wrapper-->


        <script>
            jQuery(document).ready(function() { 
                jQuery("#portfolio-list").filterable();
            });
        </script>


                </div><!-- .entry-content -->

            </div><!-- #post -->
1

To get only the parent terms you have to use the argument parent and set lvl 0. From codex:

If 0 is passed, only top-level terms are returned. Default is an empty string.

$terms = get_terms( 'tagportifolio', array( 'parent' => 0 ) );

See another question and answer here: How can I get only parent terms?

|improve this answer|||||
0

i succeed to hide from the navigation using this loop

<?php
$args = array('hide_empty'=>false,'parent'=>0);
$terms = get_terms("tagportifolio", $args );
$count = count($terms);
echo '<ul id="portfolio-filter">';
echo '<li><a href="#all" title="">All</a></li>';
if ( $count > 0 ){

    foreach ( $terms as $term ) {

        $termname = strtolower($term->name);
        $termname = str_replace(' ', '-', $termname);
        echo '<li><a href="#'.$termname.'" title="" rel="'.$termname.'">'.$term->name.'</a></li>';
    }
}
echo "</ul>";
?>
<?php 
$loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1));
$count =0;
?>

but still working on the posts query

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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