我有一个名为“Membres”(英语成员)的CPT。然后我创建了一个名为“Membres”的类别和他的子类别。
Parent category "Membres"
- Subcategory1 (3 post inside)
- Subcategory2 (4 post inside)
- Subcategory3 (1 post inside)
我需要的解决方案是生成一种循环(在循环之外),但生成我之前定义的类别的归档文件的输出(调用函数)。这将是静态页面模板的一部分。我想获得的方案是:
<h1>Title "Membres"(calls the title of the page, working)</h1>
<section>
- <h2><a>Name of "Subcategory1"</a></h2>
- <p>Description of "Subcategory1"</p>
- <posts Subcategory1>
</section>
<section>
- <h2><a>Name of "Subcategory2"</a></h2>
- <p>Description of "Subcategory2"</p>
- <posts Subcategory2>
</section>
<section>
- <h2><a>Name of "Subcategory3"</a></h2>
- <p>Description of "Subcategory3"</p>
- <posts Subcategory3>
</section>
元素有问题:<;
h2><a>Name of "Subcategory#"</a></h2>
. 我需要它作为子类别每个部分的标题(因此也可以作为类别本身的链接)。现在,我获得“类别名称”的次数与每个类别中的帖子数量一样多,但没有类别名称,只有一次。我试着到处寻找解决方案,但目前没有任何结果。我还想继续使用这个方法,不想把东西移到分类法。
wordpress中的CPT设置功能。php:
// Register Custom Post Type
function custom_post_type() {
$labels = array(
\'name\' => _x( \'Membres\', \'Post Type General Name\', \'mem\' ),
\'singular_name\' => _x( \'Membre\', \'Post Type Singular Name\', \'mem\' ),
\'menu_name\' => __( \'Membres\', \'mem\' ),
\'parent_item_colon\' => __( \'Membre principal\', \'mem\' ),
\'all_items\' => __( \'Tots els membres\', \'mem\' ),
\'view_item\' => __( \'Veure membre\', \'mem\' ),
\'add_new_item\' => __( \'Afegir membre\', \'mem\' ),
\'add_new\' => __( \'Nou membre\', \'mem\' ),
\'edit_item\' => __( \'Editar membre\', \'mem\' ),
\'update_item\' => __( \'Actualitzar membre\', \'mem\' ),
\'search_items\' => __( \'Cercar membres\', \'mem\' ),
\'not_found\' => __( \'No hi ha membres\', \'mem\' ),
\'not_found_in_trash\' => __( \'No hi ha membres a la paperera\', \'mem\' ),
);
$rewrite =<h2><?php arraysingle_cat_title(
\'slug\' => \'membre\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
\'\');
$args = array(
\'label\' => __( \'membres\', \'mem\' ),
\'description\' => __( \'Membres\', \'mem\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'revisions\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => get_bloginfo(\'template_directory\').\'/img/iconos?></users.png\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'post\',
);h2>
<p><?php echo register_post_typecategory_description( \'membres\', $args );
}
// Hook into the \'init\' action
add_actionget_category_by_slug( \'init\', \'custom_post_type\', 0 \'category_name_slug\');
我用于存档一个子类别的代码部分:
<?php query_posts(array(
\'post_type\' => \'membres\',
\'category_name\' => \'investigadors\',
\'showposts\' => 20,
->term_id )); ?>
></p>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- PART TO SOLVE-->
<h2><a>Name of "Subcategory3" Wordpress function PHP</a></h2>
<p>Description of "Subcategory3" PHP"category_description"</p>
<!-- PART TO SOLVE-->
<?php include (TEMPLATEPATH . \'/membresmem.php\'); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
?php wp_reset_postdata();?>
感谢
@CYBNET 因为提到“线索”
在查询之后和循环之前,为类别标题和类别描述添加了正确的函数:
<?php query_posts(array(
\'post_type\' => \'posttype\',
\'category_name\' => \'category\',
\'showposts\' => 20,
)); ?>
<h2><?php single_cat_title(\'\'); ?></h2>
<p><?php echo category_description( get_category_by_slug(\'category_name_slug\')->term_id ); ?></p>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>