我正在修改一个公文包主题。主题包括博客和公文包。公文包是具有各自分类法的自定义帖子类型。主题主页仅显示一个公文包。也就是说,它只显示一种自定义帖子类型的帖子。该主题显示自定义帖子类型的每个类别的最新帖子,并创建一个填充了这些类别的过滤器菜单。这样,用户可以按类别(如“graphic design”)过滤显示的帖子,JS脚本会隐藏不属于该类别的帖子。我需要混合所有投资组合的帖子和主页上的博客。因此,我需要查询所有公文包和博客中最近的所有帖子,用帖子类型填充过滤器菜单,然后将其传递给JS脚本以隐藏不属于所选帖子类型的帖子。
我已经设法查询了所有公文包和博客中最近的所有帖子,并使用下面的代码用帖子类型填充过滤器菜单:注释的代码是原始代码,例如$术语
<?php
$args=array(
\'post_type\' => array(\'post\', \'test-bscm\', \'test-btum\', \'test-other\', ),
\'posts_per_page\' => 16
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);
/*$terms = get_terms($pcat);*/
?>
//populate the filter with post types
<?php
$args=array( \'show_in_menu\' => true);
$output = \'names\';
$terms = get_post_types($args);
?>
<!-- Portfolio Filters
================================================== -->
<?php if ($home_portfoliolayout=="No Categories") {
echo \'<div class="sixteen columns row portfolio_filter" style="display: none;">\';
} else if ($home_portfoliolayout=="Categories") {
echo \'<div class="sixteen columns row portfolio_filter">\';
} ?>
<ul>
<?php
echo \'<li><a class="portfolio_selector" data-group="all-group" href="#">\'.__(\'All Projects\', \'apex\').\'</a><span>|</span></li>\';
foreach ( $terms as $term ) {
$filter_last_item = end($terms);
if($term!=$filter_last_item){
echo \'<li><a class="portfolio_selector" data-group="\'.str_replace(\' \', \'-\', $term).\'" href="#">\'.ucwords(str_replace(\'-\', \' \', $term)).\'</a><span>|</span></li>\';
}else{
echo \'<li><a class="portfolio_selector" data-group="\'.str_replace(\' \', \'-\', $term).\'" href="#">\'.ucwords(str_replace(\'-\', \' \', $term)).\'</a></li>\';
}
}
?>
</ul>
</div><div class="clear"></div>
我能够看到16篇文章,它们代表了博客的最新文章、测试bscm组合、测试bum组合和测试其他组合。过滤器显示:所有项目、帖子、页面、测试Bscm、测试Btum和测试其他。我需要从结果中删除页面,因为它不是必需的。下面是如何显示结果以及JS脚本如何隐藏帖子的代码。。。
<!-- Portfolio Teasers
================================================== -->
<div class="sixteen columns row <?php echo $folioteasers ?> portfolio">
<?php if ($wp_query->have_posts()) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php
$custom = get_post_custom($post->ID);
$foliocatlist = get_the_term_list( $post->ID, $pcat, \'\', \', \', \'\' );
$entrycategory = get_the_term_list( $post->ID, $pcat, \'\', \'_\', \'\' );
$entrycategory = strip_tags($entrycategory);
$entrycategory = strtolower($entrycategory);
$entrycategory = str_replace(\' \', \'-\', $entrycategory);
$entrycategory = str_replace(\'_\', \' \', $entrycategory);
$entrytitle = get_the_title();
$blogimageurl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
if($blogimageurl==""){
$blogimageurl = $templateurl.\'/images/demo/460x272.jpg\';
}
?>
<div class="<?php echo $foliocolumns ?> columns teaser all-group <?php echo $entrycategory ?>">
<a href="<?php the_permalink(); ?>" data-text="» <?php _e(\'Visit Project\', \'apex\'); ?>" class="hovering"><?php echo \'<img src="\'.get_template_directory_uri().\'/functions/thumb.php?src=\'.$blogimageurl.\'&h=272&w=460&zc=1" alt="" class="scale-with-grid" />\'; ?></a>
<div class="pluswrap">
<a href="<?php the_permalink(); ?>" class="bigplus"></a>
<div class="topline"><a href="<?php the_permalink(); ?>"><?php echo $entrytitle ?></a></div>
<div class="subline"><?php echo $foliocatlist ?></div>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="eleven columns row alpha">
<p><?php _e(\'Oops, we could not find what you were looking for...\', \'apex\'); ?></p>
</div>
<?php endif; ?>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
<div class="clear"></div>
</div><div class="clear"></div>
正如你所看到的,它是基于帖子类别的。因此,当我尝试按列出的帖子类型之一进行筛选时,所有结果都会隐藏。因此,解决方案是将post id与其post类型相关联。我知道它是在$custom=get\\u post\\u custom($post->ID)之后出现的;我将替换foliocatlist和entrycategory的所有代码,我只是在抄本中找不到它。谢谢