2016-04-08 15 views
-1

Özel bir posta türü "Projeler" kaydettim ve ayrıca bu Proje Türü için "Proje Kategorileri" adlı özel bir sınıflandırma kaydettim. Ana sayfamda, tüm proje ve terimleri "Proje Kategorileri" taksonomisi üzerinden listelemek istediğim bir div var. Şu anda sadece terimlerin listelerini alabiliyorum. Birisi bana neden gösterilecek şartları alamadığımı söyler. Şu anda, var:Wordpress Özel Taksonomi Ön sayfadaki

<div class="list-container"> 
    <?php 
    query_posts(array('post_type' => 'projects')); 
    if (have_posts()) : while (have_posts()) : the_post(); 
    ?> 
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
    <?php endwhile; endif; wp_reset_query(); ?> 
    <?php $taxonomy = 'project_categories'; 
    $tax_terms = get_terms($taxonomy); 
          ?> 
    <?php foreach ($tax_terms as $cat): ?> 
     <li><?php $cat; ?></li> 
    <?php endforeach; ?> 
</div><!--end list-container--> 

ben başka sorudur, query_posts döngünün içinde veya dışında taksonomiler dahil etmek daha iyidir?

+0

  • burada yankı kaçırdınız –

    cevap

    1

    get_terms($taxonomy), bir nesne dizisi döndürür (bkz. get_terms() in WP Codex), böylece adı yazdırmak için <?php echo $cat->name ?> kullanmalısınız (ve ekoyu unutmayın).

    Kodunuzu düzeltmeye çalıştım. Ayrıntılar için kod bloğunun içinde yorum bakın:

    <?php 
        // keep your queries outside the loop for more readable code 
        query_posts(array('post_type' => 'projects')); 
        $taxonomy = 'project_categories'; 
        $tax_terms = get_terms($taxonomy); 
    ?> 
    
    <!-- <li> should be enclosed in <ul> or <ol> --> 
    <ul class="list-container"> 
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
         <li><a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a></li> 
        <?php endwhile; endif; ?> 
        <?php foreach ($tax_terms as $cat): ?> 
         <li><?php echo $cat->name; ?></li> 
        <?php endforeach; ?> 
    </ul><!--end list-container--> 
    
    <?php wp_reset_query(); ?> 
    

    Sidenote: Ya <?php the_permalink(); ?> kullanın veya <a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a> kullanın. Eski tüm büyüyü otomatik olarak yapacak ve bu durumda tavsiye edilir.

    İlgili konular