2017-05-09 1 views
0
  1. Voici le code que je veux afficher mon type de message personnalisé à Filtrer les projets, de l'aide?
  2. J'ai créé type de message personnalisé qui comprennent l'image, catégorie, fichier et titre je veux faire une galerie de filtres html dynamique de la requête wp. Je veux afficher ce type de données de type personnalisé dans le code ci-dessous afin que je puisse filtrer les éléments avec la classe liée li. Voici mon html https://codepen.io/creotip/pen/dfjeFcomment afficher mon type de message personnalisé dans la galerie filtrable donnée?

    fonction 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); 
    

    Entrez le code ici

+0

où est votre code php et s'il vous plaît poster ce que avez-vous essayé – Exprator

+0

vous devez ajouter la catégorie limace à 'data-rel = » dépliants "'. et ajouter la classe à '

' – vel

+0

j'ai ajouté mon code de type de poste personnalisé ici et le code HTML est dans le codepi j'ai juste besoin et idée de la façon d'afficher un message personnalisé dans la galerie filtrable –

Répondre

0

// catégorie de filtre avec poste

<?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

Merci Marakana, comment mettre les catégories sélectionnées si j'ai d'autres catégories que ll pour les autres postes que je ne veux pas montrer dans les filtres. –

0

Imprimer la catégorie sélectionnée 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> 

Afficher la catégorie images post sage en taxonomie 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); 
?>