0

i duplicated a portfolio column page template ... On this page I want to show only one category , instead of all categories... I tried a lot, but couldn't get it worked...

this is the original code to show all categories:

<div class="container">

    <ul id="ublportfolio" class="grid cs-style-3">

        <?php 
            query_posts( array( 'post_type' => 'ublalfieportfolio', 'posts_per_page' => -1) );
            if ( have_posts() ) : while ( have_posts() ) : the_post(); 

            global $post;
            $terms = get_the_terms($post->ID, 'ublalfieportfolio-categories');
            $taxclassadd = '';
            foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

            $taxclass = 'thisportfolioitem twocol' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
        ?>

        <li <?php post_class($taxclass); ?> id="post-<?php the_ID(); ?>" data-category="<?php echo $str; ?>">
            <figure>

                <?php if(has_post_thumbnail()) { 
                $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false);
                if($thumbnail['1'] > 1024){$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large', false);} ?>
                <img src="<?php echo $thumbnail['0']; ?>" alt="<?php the_title(); ?>">
                <?php } ?>

                <figcaption>
                    <h3><?php the_title(); ?></h3>
                    <span><?php if($post->post_excerpt){$getcontent = get_the_excerpt();echo $getcontent;} ?></span>
                    <a href="<?php the_permalink(); ?>"><?php _e('View Item','ublalfie'); ?></a>
                </figcaption>

            </figure>
        </li>

        <?php endwhile; endif; ?>

    </ul>

</div>

for example I only want to show : the category-slug = "parketten" and ID = 3

I tried this:

<?php 
          query_posts( array( 'post_type' => 'ublalfieportfolio', 'category_name' => 'terrassen', 'posts_per_page' => -1) );
          if ( have_posts() ) : while ( have_posts() ) : the_post(); 

          global $post;
          $terms = get_the_terms($post->ID, 'parketten');
          $taxclassadd = '';
          foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

          $taxclass = 'span4 portfolioitem text-center' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
      ?>

result : shows nothing

<?php 
            query_posts( array( 'post_type' => 'ublalfieportfolio', 'category' => array(3), 'posts_per_page' => -1) );
            if ( have_posts() ) : while ( have_posts() ) : the_post(); 

            global $post;
            $terms = get_the_terms($post->ID, 'parketten');
            $taxclassadd = '';
            foreach($terms as $t){$taxclassadd .= ' ' . $t->slug;}

            $taxclass = 'span4 portfolioitem text-center' . $taxclassadd; $str= ltrim ($taxclassadd,' ');
        ?>

result: shows all categories..

Can someone please give me a solution... thank you very much

4
  • Are you sure it is a category and not custom taxonomy? In third section of code you should use 'cat' => 3 instead of 'category' => array(3) Commented Aug 3, 2013 at 10:26
  • thank you.. To be honest .. I think it is a custom taxonomy category.. would that be the problem? how would the code be?
    – shopowner
    Commented Aug 3, 2013 at 11:13
  • I tried with 'cat' => 3 and result: nothing shows up...
    – shopowner
    Commented Aug 3, 2013 at 11:17
  • parketten = taxonomy=ublalfieportfolio-categories&tag_ID=3&post_type=ublalfieportfolio
    – shopowner
    Commented Aug 3, 2013 at 11:18

1 Answer 1

0

You should not use category parameter to query custom taxonomy instead you should use tax_query parameter or directly custom taxonomy name as shown in the following query.

query_posts( array( 'post_type' => 'ublalfieportfolio', 'ublalfieportfolio-categories' => 'parketten', 'posts_per_page' => -1) );

Refer this page to know how to use custom taxonomy parameter in custom query.

1
  • Woohoo! You did the trick man! Great! Thank you so much!
    – shopowner
    Commented Aug 3, 2013 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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