首页 文章

如何为自定义帖子和分类法制作Wordpress存档页面?

提问于
浏览
5

我正在尝试在Wordpress中设置包含自定义帖子类型和自定义分类的存档页面 .

我创建了自定义帖子类型:“package”和自定义分类:“software” . 我的问题是,当我尝试查看localhost:8888 / software / aperture时,我得到了类型包的所有帖子,而不仅仅是选择了自定义分类光圈的帖子 . 我使用以下代码:

<?php
        $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
        ?>
        <h1><?php echo $term->name;?> Presets</h1>
        <div class="intro2">
            <p>
            <?php echo $term->description;?>
            </p>
        </div>
        <?php query_posts('post_type=package'); ?>
         <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <!-- Product Start -->
            <div class="product">
                <div class="product_top"></div>
                <div class="product_content">
                        <div class="product_image">
                        <a href="<?php the_permalink()?>">
                            <?php echo get_the_post_thumbnail( $id, $size, $attr ); ?> 
                        </div>
                        <a href="<?php the_permalink()?>" class="title"><?php the_title()?></a>
                            <?php the_excerpt()?>                   
                        <div class="theprice">
                            <?php
                            $price = get_post_meta($post->ID, "price", true);
                            echo "$".$price;
                            ?>
                        </div>
                        <a href="<?php the_permalink()?>" class="button calltoaction"><span>See The Presets</span></a>
                        <div class="clearboth"></div>
                </div>
            </div>
         <?php endwhile; else: ?>
         <p>Sorry, no posts matched your criteria.</p>
         <?php endif; ?>

如何让此存档页面只显示自定义分类中当前所选项目的类型包的帖子?

顺便说一句,我使用插件“更多类型”和“更多分类”来设置它 .

Update: solved it:

通过在更多分类法插件中将允许查询设置为true并将变量设置为预设来添加,从而解决了这个问题 . 然后我将查询更改为: <?php query_posts(array( 'post_type'=>'package', 'presets' => $term->slug, 'posts_per_page' => -1 )); ?>

1 回答

  • 1

    修改 <?php query_posts('post_type=package'); ?>

    <?php query_posts(array('post_type'=> 'package',array('taxonomy' => 'software'))); ?>
    
    or
    
    <?php query_posts(array('post_type'=> 'package','taxonomy' => 'software')); ?>
    

相关问题