我读到:Display posts of custom type in hierarchical order 但不知道是否以及如何使用答案。
这就是我想要实现的目标:
if\\u user\\u logged\\u登录
按层次顺序显示用户创建的cpost
是否可以使用此结构在主页中列出自定义帖子?
后端没有问题:
客户1(父级)the\\u title()-the\\u permalink()-edit\\u post\\u link()
第1项属于客户1的客户1子项\\u title()-第3项属于客户1的客户1子项\\u title()-第3项属于客户1的客户1子项\\u permalink()-第4项属于客户1的客户1子项-\\u permalink()-编辑\\u post\\u链接()客户2
第1项属于客户2的客户2子女第3项属于客户2的客户2子女第4项属于客户2的客户2子女-\\u permalink()-edit\\u post\\u link()等等,我想你有道理:)
以下是我注册cPost的方式:
/*Custom post clienti */
add_action( \'init\', \'register_cpt_cliente\' );
function register_cpt_cliente() {
$labels = array(
\'name\' => _x( \'Clienti\', \'cliente\' ),
\'singular_name\' => _x( \'Cliente\', \'cliente\' ),
\'add_new\' => _x( \'Aggiungi nuovo\', \'cliente\' ),
\'add_new_item\' => _x( \'Aggiungi un nuovo cliente\', \'cliente\' ),
\'edit_item\' => _x( \'Modifica cliente\', \'cliente\' ),
\'new_item\' => _x( \'Nuovo client\', \'cliente\' ),
\'view_item\' => _x( \'Guarda cliente\', \'cliente\' ),
\'search_items\' => _x( \'Cerca cliente\', \'cliente\' ),
\'not_found\' => _x( \'Nessun cliente trovato\', \'cliente\' ),
\'not_found_in_trash\' => _x( \'Nessun cliente eliminato\', \'cliente\' ),
\'parent_item_colon\' => _x( \'Cliente superiore:\', \'cliente\' ),
\'menu_name\' => _x( \'Clienti\', \'cliente\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'Un archivio per gestirli tutti (Cit.)\',
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
\'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'abruzzo\', \'basilicata\', \'calabria\', \'campania\', \'emilia-romagna\', \'friulli-venezia-giulia\', \'lazio\', \'liguria\', \'lombardia\', \'marche\', \'molise\', \'piemonte\', \'puglia\', \'san_marino\', \'sardegna\', \'sicilia\', \'toscana\', \'trentino-alto_adige\', \'umbria\', "valle_d\'aosta", \'veneto\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => get_template_directory_uri().\'/images/cli20.png\',
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\'
);
register_post_type( \'cliente\', $args );
}
这是我的循环,显然有效,但没有层次结构:
<?php if ( is_user_logged_in() ) {;?>
<div id="listaclienti-container">
<?php global $current_user;
get_currentuserinfo();
$idutente = $current_user->ID;
$loop = new WP_Query( array(
\'post_type\' => \'cliente\',
\'posts_per_page\' => -1,
\'author\' => $idutente)
);?>
<ul id="listaclienti">
<?php if (have_posts()) { ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<li>
<h3>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?><?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</a>
</h3>
</li>
<?php endwhile;
}else{echo \'No posts here\';};?>
</ul><!-- listaclienti -->
</div><!-- listaclienti Container -->
<?php };?><!-- end of if user_logged_in -->