好的,我正在使用一个模板(我已经联系了开发人员,他们没有帮助,所以我正在根据需要修改模板页面)。该模板使用以下代码显示公文包项目:
<div class="container filter-portfolio clearfix">
<ul id="portfolio" class="clearfix">
<?php
$type = \'portfolio\';
$args=array( \'post_type\' => $type, \'posts_per_page\' => -1 );
query_posts( $args );
if (have_posts()) : while (have_posts()) : the_post();
$terms = get_the_terms( $post->ID, \'portfolio_categories\' ); ?>
if (has_post_thumbnail()) {
$thumb = get_post_thumbnail_id();
$thumb_w = \'460\';
$thumb_h = \'272\';
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), \'full\');
$image_url = $image_src [0];
$attachment_url = wp_get_attachment_url($thumb, \'full\');
$image = aq_resize($attachment_url, $thumb_w, $thumb_h, true);
}
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), \'grid-thumb\');
foreach ( $terms as $term ) {
$cats[0] = $term->name;
$catname = join($cats);
$catname = preg_replace(\'/\\s/\', \'\', $catname);
}
$title= get_the_title();
$title= explode(\' \',$title);
$title[0]= \'<span class="bold">\'.$title[0].\'</span>\';
$title= implode(\' \',$title);
?>
<!-- PORTFOLIO ITEM -->
<li data-id="id-<?php echo $post->ID; ?>" data-type="<?php
$terms = get_the_term_list( $post->ID, \'portfolio_categories\',\'\',\' , \',\'\' );
$terms = preg_replace(\'/\\s/\',\'\', $terms);
$terms = strip_tags( $terms );
$terms = preg_replace(\'/[\\s,\\-!]/\',\' \', $terms);
echo $terms;
?>" class="four columns m-bot-25">
<div class="content-container-white">
<div class="view view-first">
<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" />
<div class="mask">
<h2><?php echo $title; ?></h2>
<a href="<?php echo $attachment_url; ?>" class="lightbox zoom info"></a>
<a href="<?php the_permalink(); ?>" class="link info"></a>
</div>
</div>
<div class="lw-item-caption-container">
<a class="a-invert" href="<?php the_permalink(); ?>" ><?php echo $title; ?></a>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
基本上,我只需要显示与某个slug匹配的帖子,它可以从$条件下检索。但是,当我尝试以下代码修改时:
if( $terms->slug != \'product-gallery\' ) continue;
放置在$terms=get\\u the\\u terms(…)之后行,似乎循环被打破了,页面上根本没有显示帖子。重要的是,我可以过滤帖子,并按slug进行过滤,因为我不能太多地修改主题,客户端需要能够按有slug的类别添加/删除帖子。
免责声明:我不熟悉WP环境、php和mysql。然而,我学得很快,在C++、Java、Perl等方面有丰富的编码经验。我对web开发还很陌生。
对于我的目标,我错过了什么或做错了什么?
谢谢