我使用CptUI插件创建了一个“产品”CPT。管理方面的工作似乎很好,但我无法让前端显示出我想要的效果。
例如,我创建了一个产品,比如“吉他”和另一个叫做“鼓”。他们在管理中的永久链接显示为http://mysite.com/products/guitars
和http://mysite.com/products/drums
分别看起来很棒。然而,当我导航到其中一个URL时,我会看到一个列出所有当前产品的页面。考虑到我的single-products.php
包含以下内容:
<?php
/*Template Name: Products Template
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
$mypost = array( \'post_type\' => \'products\', );
$loop = new WP_Query( $mypost );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<div style="float: right; margin: 10px">
<?php the_post_thumbnail( array( 100, 100 ) ); ?>
</div>
<strong>Name: </strong><?php the_title(); ?><br />
</header>
<div class="entry-content"><?php the_content(); ?></div>
</article>
<?php endwhile; ?>
</div>
</div>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>
我最想要的是http://mysite.com/products/guitars
仅显示带有吉他内容的单个CPT(鼓也是如此),然后http://mysite.com/products
显示所有产品(与当前的http://mysite.com/products/guitars
). 这是否可能,如果可能,如何实现?