我有我的single-{my custom post type)
页此处显示当前帖子类型。在该模式下,我想显示其他自定义帖子类型,以便导航到其他帖子类型。如何做到这一点。提前感谢
如何在Single.php中显示当前帖子类型以外的其他自定义帖子类型
2 个回复
SO网友:Gareth Gillman
您需要执行wp\\u查询以将其他帖子类型输入到您的文件中,例如。
<?php
$args = array(
\'post_type\' => \'posttype_name\',
\'posts_per_page\' => \'-1\',
\'order\' => \'DESC\'
);
$query = new WP_Query($args);
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}
wp_reset_postdata();
?>
SO网友:Mainak Ray
我知道了。。这是代码
<?php
$args=array(
\'post_type\' => \'my_post_type\',
\'post__not_in\' => array($post->ID),
\'order\'=>\'ASC\',
\'posts_per_page\'=> 3, // Number of related posts that will be shown.
\'caller_get_posts\'=>1,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
the_content();
endwhile;
?>