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

发布于 2024-11-14 01:43:45 字数 2346 浏览 4 评论 0原文

我正在尝试在 WordPress 中设置具有自定义帖子类型和自定义分类的存档页面。

我创建了自定义帖子类型:“包”和自定义分类:“软件”。我的问题是,当我尝试查看 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; ?>    

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

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

更新:解决了它:

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

I'm a trying to set up an archive page with custom post types and custom taxonomy in Wordpress.

I have created the custom post type: “package” and the custom taxonomy: “software”. My problem is that when I try to look at localhost:8888/software/aperture I get all the posts of the type package instead of just the ones with the custom taxonomy aperture selected. I am using the following code:

<?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; ?>    

How do I get this archive page to just show posts of the type package form the current selected item in the custom taxonomy?

By the way I used the plugins "More Types" and "More Taxonomies" to set it up.

Update: solved it:

Solved it myself by adding by setting Allow queries to true in the more taxonomies plugin and setting the variable to presets. Then I changed the query to:<?php query_posts(array( 'post_type'=>'package', 'presets' => $term->slug, 'posts_per_page' => -1 )); ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千紇 2024-11-21 01:43:45

修改

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

or

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

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

with

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

or

<?php query_posts(array('post_type'=> 'package','taxonomy' => 'software')); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文