我复制了公文包列页面模板。。。在此页面上,我只想显示一个类别,而不是所有类别。。。我试了很多,但都没成功。。。
这是显示所有类别的原始代码:
<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>
例如,我只想显示:类别slug=“parketten”和ID=3
我试过这个:
<?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,\' \');
?>
结果:未显示任何内容
<?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,\' \');
?>
结果:显示所有类别。。
谁能给我一个解决方案。。。非常感谢你