2014-10-22 69 views
0

我一直在尋找一種方法來獲取和輸出自定義類型的帖子標題/分類標準,而不是對標題進行硬編碼。WordPress獲取分類標題/名稱

register_taxonomy_for_object_type('category', 'portfolio'); // Register Taxonomies for Category 
register_taxonomy_for_object_type('post_tag', 'portfolio'); 
register_post_type('portfolio', // Register Custom Post Type 
    array(
    'labels' => array(
     'name' => __('Portfolio', 'html5blank'), // Rename these to suit 

我有我的模板什麼,但它打破了列,如果我把H1外面/在query_post上面再「投資組合」的稱號將不會輸出。

<section id="portfolio"> 
     <div class="row"> 
     <!-- <h3>Portfolio</h3> --> 

      <?php 
       query_posts(array('post_type' => 'portfolio')); 
       if (have_posts()) : while (have_posts()) : the_post(); 
      ?> 
<h1><?php post_type_archive_title(); ?></h1> 
       <div class="large-4 medium-4 columns"> 
        <?php echo the_content(); ?> 
        <!-- <br class="clear"> --> 
        <h3> 
         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> 
        </h3> 
        <br class="clear"> 

        <?php edit_post_link(); ?> 
       </div> 

      <?php endwhile; endif; wp_reset_query(); ?> 
     </div> 
    </section> 

enter image description here

所以我想輸出「組合」我的模板,我試過,但我很困惑如何獲得註冊的名稱。

<?php 
$terms = get_terms('my-taxonomy-name'); 
foreach ($terms as $term) { 
echo $term->slug.' '; 
} 
?> 

編輯:

<?php 
       global $wp_post_types; 
       $obj = $wp_post_types['portfolio']; 
       echo "<h3>"; 
        echo $obj->labels->name; 
       echo "</h3>"; 
      ?> 

回答

0

也許您正在尋找get_post_type_object()功能:

$obj = get_post_type_object('portfolio'); 
echo $obj->labels->name; 

獲得註冊的標籤爲portfolio自定義後的類型。

+0

不起作用,但我把全球以及那麼它的工作:/ – nCore 2014-10-22 06:49:23

+0

你把全球放在什麼? ps:你不應該按照Codex中的解釋使用'query_posts()'。 – birgire 2014-10-23 13:46:54

+0

看到我的編輯,我用query_post來輸出自定義後期類型。 – nCore 2014-10-23 15:23:31