如何在给定的可过滤画廊中显示我的自定义帖子类型?

问题描述:

  1. 这里是我想要显示我的自定义帖子类型的代码 筛选项目,有什么帮助吗?
  2. 我创建了自定义帖子类型,其中包括图像, 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

哪里是你的PHP代码,并请发表你尝试过什么 – Exprator

+0

你必须类别废料添加到'数据的rel =”传单“'。并将类添加到'

' – vel
+0

我在这里添加了我的自定义帖子类型代码,并且html在codepi中,我只需要以及如何在可筛选画廊中显示自定义帖子的想法 –

//过滤类别与交

<?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,如何将选定的类别放入其他类别中在过滤器中显示。 –

打印选定类别中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); 
?>