【问题标题】:WordPress custom post type Single.php?WordPress 自定义帖子类型 Single.php?
【发布时间】:2011-08-31 17:37:49
【问题描述】:

我有一个 WordPress 自定义帖子类型设置。我已经创建了

single-[customposttype].php 

但是,它不是只显示请求的自定义帖子类型,而是转到 URL,然后显示自定义类型中的所有帖子。

这是我目前正在使用的代码的副本:

    <?php query_posts("post_type=shorts"); while (have_posts()) : the_post(); ?>

<div class="header-promo">
    <?php echo get_post_meta($post->ID, "mo_short_embed", true); ?>
</div>
<div class="content-details">   
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
</div>

<?php endwhile; ?>

提前致谢:)

【问题讨论】:

标签: wordpress wordpress-theming custom-post-type


【解决方案1】:

答案是删除

query_posts("post_type=shorts");

这仅在拉入自定义帖子类型的多个帖子时需要,例如创建档案风格的页面。

【讨论】:

  • 啊,这是有道理的,因为在自定义 slug 上拉出帖子类型是多余的。很高兴你明白了。
【解决方案2】:

尝试添加“posts_per_page”并将其设置为 1。

query_posts(
 'post_type' => 'shorts',
 'posts_per_page' => 1
)

【讨论】:

  • 感谢您的回复,但这是从“短裤”帖子类型中获取的第一个帖子,而不是选择的那个。
猜你喜欢
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
  • 1970-01-01
相关资源
最近更新 更多