カテゴリとサブカテゴリ(存在する場合)でメニューを取得します。 私のカスタムポストタイプはfunctions.phpで宣言し、テーマで実行します。Wordpressはカテゴリとサブカテゴリで投稿タイプを分割します
マイfunction.phpコード:
function register_lekarze(){
$labels = array(
'name' => _x('Lekarze', 'post type general name', '__freshview__'),
'singular_name' => _x('Lekarze', 'post type singular name', '__freshview__'),
'menu_name' => _x('Lekarze', 'admin menu', '__freshview__'),
'name_admin_bar' => _x('Lekarze', 'add new on admin bar', '__freshview__'),
'add_new' => _x('Dodaj nowego', '__freshview__'),
'add_new_item' => __('Dodaj nowego', '__freshview__'),
'new_item' => __('Nowy', '__freshview__'),
'edit_item' => __('Edytuj', '__freshview__'),
'view_item' => __('Zobacz', '__freshview__'),
'all_items' => __('Wszyscy', '__freshview__'),
'search_items' => __('Szukaj', '__freshview__'),
'parent_item_colon' => __('Nadrzędny:', '__freshview__'),
'not_found' => __('Nie znaleziono.', '__freshview__'),
'not_found_in_trash' => __('Nie znaleziono w koszu.', '__freshview__')
);
$args = array(
'labels' => $labels,
'description' => __('Lekarze', '__freshview__'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('title', 'thumbnail', 'page-attributes'),
'menu_icon' => 'dashicons-id'
);
register_post_type('lekarze', $args);
register_taxonomy("categories", array("lekarze"),
array(
"hierarchical" => true,
"label" => "Kategorie",
"singular_label" => "Kategoria",
"rewrite" => array('slug' => 'kategoria', 'with_front'=> true)));
} add_action( 'のinit'、 'register_lekarze')。
マイコード:私が欲しいもの
<?php
$args = array (
'post_type' => 'lekarze',
'posts_per_page' => -1,
'order' => 'ASC',
'tax_query' => array(
array (
'taxonomy' => 'categories',
'field' => 'slug',
'terms' => 'lekarze',
)
),
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$i=1;
while ($query->have_posts()) {
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$query->the_post();
$fields = get_fields();
if($actual_link == get_the_permalink()){
$class = 'current';
}else{
$class= '';
}
?>
<li class="<?php echo $class;?>"><a href="<?php echo get_the_permalink();?>"><?php echo get_the_title(); ?></a></li>
<?php
$i++;
}
wp_reset_postdata();
}
?>
がメニューにこのような何かを得ることです:
Lekarze(医者 - >神経科 - 医師の名前とパーマリンクの>リスト)