Answer the question
In order to leave comments, you need to log in
How to implement a list of categories of a custom post?
Making a simple catalog based on Custom Post Type
Created a custom post with the ability to add a category
<?php
// Register Custom Post Type
function custom_post_type_project() {
$labels = array(
'name' => 'Галерея',
'singular_name' => 'Gallery',
'menu_name' => 'Галерея',
'add_new_item' => 'Добавить новый',
'add_new' => 'Добавить новый',
'new_item' => 'Новая',
'edit_item' => 'Редактировать',
'update_item' => 'Обновить',
'view_item' => 'Просмотр',
'view_items' => 'Посмотреть все',
);
$rewrite = array(
'slug' => 'gallery',
'with_front' => true,
'pages' => false,
'feeds' => false,
);
$args = array(
'label' => 'Галерея',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'editor'),
'taxonomies' => array('category'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 7,
'menu_icon' => 'dashicons-format-image',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'query_var' => 'gallery',
'rewrite' => $rewrite,
);
register_post_type( 'gallery', $args );
}
add_action( 'init', 'custom_post_type_project', 0 );
Answer the question
In order to leave comments, you need to log in
<?php
$terms = get_terms( array(
'taxonomy' => 'category',
'orderby' => 'name',
'hide_empty' => false,
'count' => false,
'hierarchical' => true,
) );
$terms = wp_list_filter( $terms, array('parent'=>0) ); // Если надо вывести только рубрики верхнего уровня
?>
<?php
if( $terms && ! is_wp_error($terms) ){
foreach( $terms as $term ){
echo "<a href='". get_term_link( (int) $term->term_id, 'category' ) ."'>". $term->name ."</a>";
}
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question