Мне нужно сделать цикл для портфеля, отфильтрованного по категориям.Я создал пользовательский тип сообщения (CPT), и мне нужно зациклить категории и создать цикл для сообщений этой категории.
<!-- categories loop -->
<div id="bl-main" class="bl-main">
<!-- Portfolio Starts -->
<section id="bl-work-section1" class="section-port">
<div class="bl-box valign-wrapper">
<div class="page-title center-align">
<h2 class="center-align"><span data-hover="category1">category Name</span>
</h2>
</div>
</div>
<div class="bl-content">
<!-- Main Heading Starts -->
<div class="container page-title center-align">
<h2 class="center-align">
<span data-hover="portfolio">category 1</span>
</h2>
</div>
<!-- Main Heading Ends -->
<div class="container">
<!-- Divider Starts -->
<div class="divider center-align">
<span class="outer-line"></span>
<span class="fa fa-suitcase" aria-hidden="true"></span>
<span class="outer-line"></span>
</div>
<!-- Divider Ends -->
<div class="row center-align da-thumbs" id="bl-work-items1">
<!-- Portfolio posts supposed to loop here -->
<!-- Project Starts -->
<div class="col s12 m6 l6 xl4" data-panel="panel-1">
<a href="#">
<img class="responsive-img" src="https://via.placeholder.com/300" alt="Project" />
<div class="align-wrapper"><span class="font-weight-700 uppercase">Image Project</span></div>
</a>
</div>
<!-- Project Ends -->
</div>
</div>
</div>
<!-- Portfolio Expanded Ends -->
<i class="bl-icon-close fa fa-close" ></i>
</section>
</div>
</div>
Вторая проблема заключается в том, что когда я регистрирую пользовательский пост, он разделяет категориинормальные сообщения.
function portfolio_register() {
$labels = array(
'name' => _x('Portfolio', 'post type general name'),
'singular_name' => _x('Portfolio Item', 'post type singular name'),
'add_new' => _x('Add New', 'portfolio item'),
'add_new_item' => __('Add New Portfolio Item'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio Item'),
'search_items' => __('Search Portfolio Items'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 8,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'portfolio' , $args );
}
add_action('init', 'portfolio_register');
function create_portfolio_taxonomies() {
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Categories' ),
);
$args = array(
'hierarchical' => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'categories' ),
);
register_taxonomy( 'portfolio_categories', array( 'portfolio' ), $args );
}
add_action( 'init', 'create_portfolio_taxonomies', 0 );
Я пытался гуглить, я пробовал много кодов, но он показывает только одну из категорий, поэтому, пожалуйста, помогите.