2017-05-09 56 views
0
  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中,我只需要以及如何在可篩選畫廊中顯示自定義帖子的想法 –

回答

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); 
?> 
相關問題