我刚刚开始关注自定义帖子类型,由于某些原因,无法在循环中显示任何自定义帖子类型。我在网上发现了一些查询,但它们都不在封闭的php语句中,我不知道如何集成它们。以下是我所拥有的:
// add custom post type
add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'band_artists\',
array(
\'labels\' => array(
\'name\' => __( \'Artists\' ),
\'singular_name\' => __( \'Artist\' )
),
\'public\' => true,
\'has_archive\' => true,
\'supports\' => array( \'title\', \'editor\', \'comments\', \'excerpt\', \'custom-fields\', \'thumbnail\' ),
\'rewrite\' => array(\'slug\' => \'artists\'),
\'taxonomies\' => array(\'category\', \'post_tag\')
)
);
}
并使用随机化器进行查询。。。当这些只是普通的帖子(减去\'post_type\'
显然)。<?php query_posts(array(
\'post_type\' => \'band_artists\',
\'showposts\' => 1,
\'orderby\' => \'rand\',
\'category\' => \'5\'
));
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div id="post-<?php the_ID(); ?>" class="artistSingle">
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<div id="artistImgSingle"><?php the_post_thumbnail(\'medium\'); ?></div>
<?php endif; ?>
<p class="artistName"><?php the_title(); ?></p>
<p>
<?php if(get_post_meta($post->ID, \'band\', true)): ?>
<strong>Band:</strong> <?php echo get_post_meta($post->ID, \'band\', true); ?><br />
<?php endif; ?>
<?php if(get_post_meta($post->ID, \'gear\', true)): ?>
<strong>Gear:</strong> <?php echo get_post_meta($post->ID, \'gear\', true); ?><br>
<?php endif; ?>
<?php if(get_post_meta($post->ID, \'website\', true)): ?>
<strong>Website:</strong> <a href="http://<?php echo get_post_meta($post->ID, \'website\', true); ?>" target="_blank"><?php echo get_post_meta($post->ID, \'website\', true); ?></a>
<?php endif; ?>
</p>
<?php the_content(); ?>
<div>
<?php wp_link_pages( array( \'before\' => \'<div class="page-link"><span>\' . __( \'Pages:\', \'2012\' ) . \'</span>\', \'after\' => \'</div>\' ) ); ?>
</div>
</div>
<?php endwhile; // end of featured large loop ?>
<?php else : ?>
<?php endif; ?>