2016-10-27 6 views
-1

私はwordpressでポートフォリオを作りたいと思っています。 正常に動作していますが、h2タイトルの下で、h3のポートフォリオのカテゴリを確認したいと思います。Array wordpress php

その他の質問。

リンクはタイトルh2でしか機能しません。このリンクはキャプションの上にリンクとして表示されたかったと思います。

コードに関するアドバイスは歓迎します!

答えて

1

この

<?php 
 
     $args = array('post_type' => 'portfolio', 'posts_per_page' => -1); 
 
     $loop = new WP_Query($args); 
 
\t $terms = get_the_terms($post->ID, 'portfolio-categories'); \t \t \t \t \t \t 
 
      if ($terms && ! is_wp_error($terms)) : 
 
    
 
       $links = array(); 
 
    
 
       foreach ($terms as $term) { 
 
        $links[] = $term->name; 
 
       } 
 
    
 
       $tax_links = join(" ", str_replace(' ', '-', $links));   
 
       $tax = strtolower($tax_links); 
 
      else : \t 
 
\t  $tax = ''; \t \t \t \t \t 
 
      endif; 
 
\t  
 
     while ($loop->have_posts()) : $loop->the_post(); 
 
\t \t \t \t 
 
\t \t \t \t echo '<div class="row-masonry">'; 
 
\t \t \t \t echo '<div class="item">'; 
 
\t \t \t \t echo '<div class="well portfolio-item no-gutter">'; 
 
\t \t \t \t echo '<div class="thumbnail no-gutter">'. get_the_post_thumbnail() .'</div>'; 
 
\t \t \t \t echo '<div class="caption">'; 
 
\t \t \t \t echo '<div class="vertical-align">'; 
 
\t \t \t \t $link = get_the_permalink(); 
 
       echo "<a href=$link>"; 
 
       echo '<h2>'. get_the_title() .'</h2>'; 
 
\t \t \t 
 
       I want to see here the portfolio image category in h3 
 
    
 
       echo "</a>"; 
 
\t \t \t \t echo '</div>'; /*close caption*/ 
 
\t \t \t \t echo '</div>'; /*close caption*/ 
 
\t \t \t \t echo '</div>'; 
 
\t \t \t \t 
 
\t \t \t \t echo '</div>'; 
 
\t \t \t \t endwhile; 
 
\t \t \t \t echo '</div>'; 
 
\t \t \t \t echo '</div>'; 
 
\t \t \t \t echo '</div>'; 
 
\t \t \t \t 
 
\t \t ?> 
 
     
 
    
 

 
    
 
    </div><!-- #page -->
はあなたのために働く必要がありますどうもありがとう。あなたはどのように投稿のカテゴリを取得することができますGoogle。あなたの答えが得られますが、これはうまくいくでしょう。

<?php 
$args = array('post_type' => 'portfolio', 'posts_per_page' => -1); 
$loop = new WP_Query($args); 
$terms = get_the_terms($post->ID, 'portfolio-categories'); 
if ($terms && ! is_wp_error($terms)) : 

    $links = array(); 

    foreach ($terms as $term) { 
     $links[] = $term->name; 
    } 

    $tax_links = join(" ", str_replace(' ', '-', $links)); 
    $tax = strtolower($tax_links); 
else : 
    $tax = ''; 
endif; 

while ($loop->have_posts()) : $loop->the_post(); 

    echo '<div class="row-masonry">'; 
    echo '<div class="item">'; 
    echo '<div class="well portfolio-item no-gutter">'; 
    echo '<div class="thumbnail no-gutter">'. get_the_post_thumbnail() .'</div>'; 
    echo '<div class="caption">'; 
    echo '<div class="vertical-align">'; 
    $link = get_the_permalink(); 
    echo "<a href=$link>"; 
    echo '<h2>'. get_the_title() .'</h2>'; 

    // GET THE CATEGORY -- Returns an array of all categories 
    // $categories = get_the_category(); 
    $categories = get_the_terms(get_the_ID(), 'portfolio-categories'); // for custom taxnomies 

    // If not an empty array then show the first category set 
    if (! empty($categories)) { 
     echo "<h3>" . esc_html($categories[0]->name) ."</h3>"; 
    } 



       echo "</a>"; 
       echo '</div>'; /*close caption*/ 
       echo '</div>'; /*close caption*/ 
       echo '</div>'; 

       echo '</div>'; 
endwhile; 
echo '</div>'; 
echo '</div>'; 
echo '</div>'; 

?> 




</div><!-- #page --> 
+0

この「$ categories = get_the_terms($ id、 'portfolio-categories');」 – Radmation

+0

ありがとうございます!それは完全に動作します!あなたは私を救った;-) – Nicola

+0

@ニコラ問題はありません。それがこのコミュニティがここにいる理由です。今あなたが私に答えを与えてもらえないのであれば...。ありがとう:D – Radmation