如何为自定义帖子和分类法制作 WordPress 存档页面?
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修改
与
Modify
<?php query_posts('post_type=package'); ?>
with