开发者

WordPress custom post type Single.php?

开发者 https://www.devze.com 2023-01-20 03:58 出处:网络
I have a WordPress custom post-type setup. I\'ve created single-[customposttype].php However instead of displaying only the requested custom-post-type it goes to the URL, then displays all of the

I have a WordPress custom post-type setup. I've created

single-[customposttype].php 

However instead of displaying only the requested custom-post-type it goes to the URL, then displays all of the posts in the custom-type.

Here's a copy of the code i'm currently using:

    <?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); 开发者_C百科?>
</div>
<div class="content-details">   
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
</div>

<?php endwhile; ?>

Thanks in advance :)


Answer was to remove

query_posts("post_type=shorts");

This is only needed for pulling in multiple posts of a custom-post-types, e.g. to create an Archives-style page.


Try adding a "posts_per_page" and setting it to 1.

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

精彩评论

暂无评论...
验证码 换一张
取 消