- 这里是我想要显示我的自定义帖子类型的代码 筛选项目,有什么帮助吗?
我创建了自定义帖子类型,其中包括图像, catagory,文件和标题我想做一个过滤器画廊html 动态从wp查询。我想在下面的代码中显示该自定义的帖子类型数据,以便我可以用li相关的类来过滤项目。 这里是我的html https://codepen.io/creotip/pen/dfjeF如何在给定的可过滤画廊中显示我的自定义帖子类型?
功能custom_post_type(){
$labels = array( 'name' => _x('Audio', 'Post Type General Name', 'twentythirteen'), 'singular_name' => _x('Audio', 'Post Type Singular Name', 'twentythirteen'), 'menu_name' => __('Audio', 'twentythirteen'), 'parent_item_colon' => __('Parent Movie', 'twentythirteen'), 'all_items' => __('All Audio', 'twentythirteen'), 'view_item' => __('View Audio', 'twentythirteen'), 'add_new_item' => __('Add New Audio', 'twentythirteen'), 'add_new' => __('Add New', 'twentythirteen'), 'edit_item' => __('Edit Audio', 'twentythirteen'), 'update_item' => __('Update Audio', 'twentythirteen'), 'search_items' => __('Search Audio', 'twentythirteen'), 'not_found' => __('Not Found', 'twentythirteen'), 'not_found_in_trash' => __('Not found in Trash', 'twentythirteen'), ); // Set other options for Custom Post Type $args = array( 'label' => __('audio', 'twentythirteen'), 'description' => __('Audio news and reviews', 'twentythirteen'), 'labels' => $labels, 'supports' => array('title', 'editor', 'thumbnail', 'comments', ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', // This is where we add taxonomies to our CPT 'taxonomies' => array('category'), ); // Registering your Custom Post Type register_post_type('audio', $args); } /* Hook into the 'init' action so that the function * Containing our post type registration is not * unnecessarily executed. */ add_action('init', 'custom_post_type', 0);
在这里输入的代码
0
A
回答
0
//过滤类别与交
<?php
$category_args = array(
'taxonomy' => 'category',
'hide_empty' => 0,
'depth' => 0,
'hierarchical' => true,
'exclude' => '1',
'orderby' => 'ID',
'order' => 'ASC'
);
$category_args_array = get_categories($category_args);
if (!empty($category_args_array))
{
$category_args_count=0;
?>
<div class="toolbar mb2 mt2">
<button class="btn fil-cat" href="" data-rel="all">All</button>
<?php
foreach ($category_args_array as $category_args_category)
{
$category_args_count++;
$category_args_id = $category_args_category->term_id;
$category_args_name = $category_args_category->cat_name;
$category_args_slug = $category_args_category->slug;
$category_args_slug = str_replace('-', '_', $category_args_slug);
?>
<button class="btn fil-cat" data-rel="<?php echo $category_args_slug;?>"><?php echo $category_args_name;?></button>
<?php
}
?>
</div>
<?php
}
?>
<div style="clear:both;"></div>
<?php
$audio_type = 'audio';
$audio_args=array(
'type' => $audio_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => -1,
'orderby' => 'id',
'order' => 'ASC'
);
$audio_my_query = null;
$audio_my_query = new WP_Query($audio_args);
if($audio_my_query->have_posts())
{
?>
<div id="portfolio">
<?php
while ($audio_my_query->have_posts()) : $audio_my_query->the_post();
$term_name_array = wp_get_post_terms($post->ID, 'category', array("fields" => "slug"));
$term_name = $term_name_array[0];
$class_term_name = str_replace('-', '_', $term_name);
if (has_post_thumbnail()) {
//get_the_post_thumbnail($post->ID, array(100, 100));
?>
<div class="tile scale-anm <?php echo $class_term_name?> all">
<?php echo get_the_post_thumbnail($post->ID,"thumbnail"); //thumbnail,medium,large,full,array(100,100)?>
</div>
<?php
}
endwhile;
?>
</div>
<?php
}
wp_reset_query($audio_my_query);
?>
<div style="clear:both;"></div>
+0
谢谢Marakana,如何将选定的类别放入其他类别中在过滤器中显示。 –
0
打印选定类别中taxonomy-category.php
<?php
$category_object=get_queried_object();
$category_term_id = $category_object->term_id;
$category_term_name = $category_object->cat_name;
?>
<h1><?php echo $category_term_name;?></h1>
Display类的明智后的图像在分类学category.php
<?php
$audio_type = 'audio';
$audio_args=array(
'type' => $audio_type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $category_term_id
)
),
'orderby' => 'id',
'order' => 'ASC'
);
$audio_my_query = null;
$audio_my_query = new WP_Query($audio_args);
if($audio_my_query->have_posts())
{
?>
<div id="portfolio">
<?php
while ($audio_my_query->have_posts()) : $audio_my_query->the_post();
$term_name_array = wp_get_post_terms($post->ID, 'category', array("fields" => "slug"));
$term_name = $term_name_array[0];
$class_term_name = str_replace('-', '_', $term_name);
if (has_post_thumbnail()) {
//get_the_post_thumbnail($post->ID, array(100, 100));
?>
<div class="tile scale-anm <?php echo $class_term_name?> all">
<?php echo get_the_post_thumbnail($post->ID,"thumbnail"); //thumbnail,medium,large,full,array(100,100)?>
</div>
<?php
}
endwhile;
?>
</div>
<?php
}
wp_reset_query($audio_my_query);
?>
相关问题
- 1. 显示帖子数自定义帖子类型的子类别
- 2. 如何在子菜单中显示自定义帖子类型?
- 3. 如何显示来自特定自定义帖子类型的帖子
- 4. 显示页面中的自定义帖子类型帖子
- 5. 在页脚上显示自定义帖子类型的帖子
- 6. Wordpress显示自定义帖子类型
- 7. 如何在wordpress中显示自定义帖子类型的单独帖子
- 8. 如何在自定义帖子类型中显示最多查看的帖子
- 9. 如何使用自定义帖子类型在父帖子类型中显示子帖子类型?
- 10. WordPress按自定义分类标准显示自定义帖子类型帖子
- 11. 要显示具有自定义帖子类型的帖子
- 12. WordPress的:get_categories自定义帖子类型,自定义分类,按类别过滤
- 13. 仅显示特定类别的自定义帖子类型
- 14. 在自定义帖子列表中显示帖子的分类
- 15. 如何使用URL过滤wordpress自定义帖子类型?
- 16. 如何在最新的Wordpress RESTful API中通过自定义分类过滤自定义帖子类型?
- 17. 如何显示WordPress自定义帖子类型的列表?
- 18. WordPress的,如何通过自定义帖子类型的分类过滤
- 19. 未在前端显示自定义类别的Wordpress自定义帖子类型
- 20. 在自定义帖子类型列表中显示自定义分类列
- 21. 自定义帖子类型给出404
- 22. 如何修改Taxonomy.php以显示自定义帖子类型和自定义分类标准的所有帖子?
- 23. 如何仅显示自定义帖子类型的精选帖子?
- 24. 一个特定的Wordpress自定义帖子类型不显示
- 25. 从多个自定义帖子类型中显示某个类别的帖子
- 26. 为什么我的自定义帖子类型帖子不显示?
- 27. Wordpress:在帖子视图中显示自定义类型帖子的列表
- 28. WordPress的过滤器自定义帖子类型与JSON API
- 29. WordPress的:显示自定义帖子类型Alphabetized自定义分类?
- 30. 自定义帖子类型
哪里是你的PHP代码,并请发表你尝试过什么 – Exprator
你必须类别废料添加到'数据的rel =”传单“'。并将类添加到'
我在这里添加了我的自定义帖子类型代码,并且html在codepi中,我只需要以及如何在可筛选画廊中显示自定义帖子的想法 –