2017-01-02 54 views
0

CPT =自定義帖子類型自定義發佈分類標準列表

我已經創建了一個在我的wordpress中完美工作的CPT。

下面的代碼:

register_post_type('clases-tinka', 
// CPT Options 
    array(
     'labels' => array(
      'name' => __('Academy'), 
      'singular_name' => __('Academy') 
     ), 
     'public' => true, 
     'has_archive' => true, 
     'rewrite' => array('slug' => 'tinka-academy'), 
     // Features this CPT supports in Post Editor 
     'supports'   => array('title', 'editor', 'excerpt', 'thumbnail', 'comments'), 
     'has_archive'   => false, 
     'exclude_from_search' => false, 
     'publicly_queryable' => true, 
     'capability_type'  => 'page', 
     'taxonomies' => array('academy-tax','category'), 

    ) 


); 

我循環所有CPT一個PHP文件中,你可以在這裏看到http://tinka.com.co/es/tinka-academy/

下面的代碼:

$i = 1; 
    //added before to ensure it gets opened 
    echo '<div class="row-cursos">'; 
    $wp_query = new WP_Query(array('post_type' => 'clases-tinka', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC')); 
    if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); 
     // post stuff... 
      ?> 

      <div class="col-xs-12 col-sm-6 col-md-4"> 

       <div class="clasesclass"> 
        <div><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div> 
        <div><a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a></div> 
        <div class="datosclase"> 

         <?php 
         $horast = get_field('horas_del_curso'); 
         $diast = get_field('dias_split'); 
         $personast = get_field('cantidad_de_personas'); 

         ?> 

         <h4><?php if ($horast == "1") { echo "Curso de " .$horast. " Hora";} else { echo "Curso de " .$horast . " Horas";} ?></h4> 
         <h4><?php echo $diast ?></h4> 
         <h4><?php if ($personast == "1") { echo "Grupo de " . $personast ." Persona";} else { echo "Grupo de " .$personast ." Personas";} ?></h4> 
         <p>Category: <?php $terms = get_terms("academy-tax"); $count = count($terms); if ($count > 0){ foreach ($terms as $term) { echo $term->name; } } ?> 
    </p> 


        </div> 
        <div class="botonenlace"> 
         <a href="<?php the_permalink(); ?>" target="_self" class="tcvpb-button tcvpb-button_red tcvpb-button_rounded tcvpb-button_small ripplelink ">Ver Más<i class="typicons-media-play"></i></a> 
        </div> 
       </div> 
      </div> 


      <?php 
     // if multiple of 3 close div and open a new div 
     if($i % 3 == 0) {echo '<div style="clear:both"></div></div><div class="row-cursos"><hr>';} 

    $i++; endwhile; endif; 
    //make sure open div is closed 
    echo '</div>'; 


    ?> 

    </div> <!-- Container End --> 

    <div class="container"> 
    <?php 
    $terms = get_the_terms('clases-tinka', 'category'); 

    // Want a list of category here 

    ?> 
    </div> 

我不很好地理解分類法是如何工作的,我只想列出在該CPT中創建的類別。

回答

0

你的意思是你想要在PHP的底部列出每個課程類別,對不對?

那麼,對於初學者來說,函數get_the_terms()只會檢索附加到給定帖子的條款(通過ID或帖子對象本身)。

您應該看看get_taxonomies()函數。有了這個,你可以查詢你的CPT類別。

+0

我一直在搜索無法弄清楚它如何做任何形式的幫助將是偉大的! –

相關問題