2017-12-22 9 views
1

私のカテゴリのpostsループにカスタムデータを表示する必要があります。私は自分の投稿テンプレートに特別なdivを作成したいと思っています。この投稿のループにこのdivのデータを表示したいのです。誰でも助けてくれますか?ありがとうWordpress postsループでカスタムデータを表示する

<?php 
    if (have_posts()) : 
    query_posts('cat=7'); 
    while (have_posts()) : the_post(); ?> 
    <div class = "item"> 
    <div class="item_image"><?php the_post_thumbnail(); ?></div> 
     <div class = "item_title"><?php the_title(); ?></div> 
     <div class = "item_excerpt"><?php the_excerpt(10); ?></div> 
     <!-- here I want to display data from each post --> 
     <div class = "my_custom_data">custom data</div> 
     <a href = "<?php the_permalink(); ?>" class = "item_link">Show more...</a> 
    </div> 
    <?php endwhile;    
    endif; 
    wp_reset_query(); 
?> 
+1

であれば、フィールドの名前例えばを取得する必要がありますか?どうしたの?ここでお勧めのhttps://codex.wordpress.org/Custom_Fieldsや独自のカスタムフィールドを作成することができます – omukiguy

+1

@omukiguy ACFプラグインでカスタムフィールドを作成し、データを追加しました。今、私はサムネイル、タイトルなどを表示するsingle.phpテンプレートとpage-blog.php(たとえば)ループにこのデータを表示したいと思います。 –

答えて

0

ACFには2つの強力な関数get_field()とthe_field()があります。フィールド値を変数として取得するには、get_field()関数を使用します。これは、あらゆるタイプのフィールドの値を常に返す最も汎用性の高い関数です。

フィールドを表示するには、the_field()も同様の方法で使用します。

は、今あなたが情報を持つカスタムフィールドを追加したそれはcustom_title "

<?php 
    if (have_posts()) : 
    query_posts('cat=7'); 
    while (have_posts()) : the_post(); ?> 
    <div class = "item"> 
    <div class="item_image"><?php the_post_thumbnail(); ?></div> 
     <div class = "item_title"><?php the_title(); ?></div> 
     <div class = "item_excerpt"><?php the_excerpt(10); ?></div> 
     <!-- here I want to display data from each post --> 
     <div class = "my_custom_data"><?php the_field('custom_title'); ?></div> 
     <a href = "<?php the_permalink(); ?>" class = "item_link">Show more...</a> 
    </div> 
    <?php endwhile;    
    endif; 
    wp_reset_query(); 
?> 
+0

を私の投稿テンプレート.phpなど)。私はポストに 'custom_title'を入力し、それをポストとこのループの両方に表示したいという意味です。 –

+0

single.phpはまた、whileループを有する ' \t \t \t

omukiguy

+0

投稿クエリのループに「

」を追加するだけです。私はこれがはっきりしていることを望む – omukiguy

関連する問題