2017-01-16 11 views
0

投稿IDを使用して2つの特定の投稿を表示しようとしています。しかし私はポストIDを呼び出すためにどのコードを使うのか分かりません。誰か助けてくれますか?投稿IDを使用して特定の投稿を表示する方法

///////////////////////////////

/////////// ///////////////////

<div class="food-featured-posts"> 
 
    <div class="food-featured-posts-first"> 
 
     <?php query_posts('p=185'); ?> 
 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
 
      <div class="popular-sticker">Popular</div> 
 
     </div> 
 
     <div class="food-featured-posts-info"> 
 
      <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
 
      <?php get_template_part('share-buttons'); ?> 
 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
 
     </div> 
 
    </div> 
 
    <div class="food-featured-posts-second"> 
 
     <?php query_posts('p=173'); ?> 
 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
 
      <div class="popular-sticker">Popular</div> 
 
     </div> 
 
     <div class="food-featured-posts-info"> 
 
      <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
 
      <?php get_template_part('share-buttons'); ?> 
 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
 
     </div> 
 
    </div> 
 
</div> 
 
<h1 class="latest-in-food">Latest in food</h1>

更新コード

<?php 
 
$args = array(
 
    'post_type' => 'post', 
 
    'meta_key' => '_thumbnail_id', 
 
    'p' => 185/173, 
 
$query = new WP_Query($args); 
 

 
<div class="food-featured-posts"> 
 
<?php while($query->have_posts()) : $query->the_post(); ?> 
 
    <div class="food-featured-posts-first"> 
 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
 
      <div class="popular-sticker">Popular</div></div> 
 
     <div class="food-featured-posts-info"> 
 
     <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
 
      <?php get_template_part('share-buttons'); ?> 
 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
 
     </div></div> 
 

 
    <?php endwhile; ?> 
 

 
<?php while($query->have_posts()) : $query->the_post(); ?> 
 
    <div class="food-featured-posts-second"> 
 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
 
      <div class="popular-sticker">Popular</div></div> 
 
     <div class="food-featured-posts-info"> 
 
     <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
 
      <?php get_template_part('share-buttons'); ?> 
 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
 
     </div></div> 
 
    <?php endwhile; ?> 
 

 
</div> 
 
?> 
 

 
<h1 class="latest-in-food">Latest in food</h1>

答えて

0
<?php 
    $args = array(
    'post_type' => 'post',  
    'p' => 173, 
    $query = new WP_Query($args); 

    <div class="food-featured-posts"> 
    <?php while($query->have_posts()) : $query->the_post(); ?> 
    <div class="food-featured-posts-first"> 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
      <div class="popular-sticker">Popular</div></div> 
     <div class="food-featured-posts-info"> 
     <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
      <?php get_template_part('share-buttons'); ?> 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
     </div></div> 

    <?php endwhile; 
    wp_reset_query(); 

    $args1 = array(
    'post_type' => 'post',   
    'p' => 185, 
    $anotherQuery = new WP_Query($args1); 
    ?> 

    <?php while($anotherQuery->have_posts()) : $anotherQuery->the_post(); ?> 
    <div class="food-featured-posts-second"> 
     <div class="food-wrapper"><?php the_post_thumbnail(); ?> 
      <div class="popular-sticker">Popular</div></div> 
     <div class="food-featured-posts-info"> 
     <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> 
      <?php get_template_part('share-buttons'); ?> 
      <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> 
      <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> 
     </div></div> 
    <?php endwhile; 
    wp_reset_query(); 
    ?> 

    </div> 
    ?> 
+0

にはどうすれば効果的にこのコードはintを追加しますo私のコードは? – user6738171

+0

http://wordpress.stackexchange.com/questions/89202/query-posts-only-with-featured-imageフィーチャーイメージ/タイトルのこのリンクを確認してください。 –

+0

元の回答の更新されたコードが好きですか?申し訳ありませんが、私はまだ最高のPHPではないので、私はそれを書く方法をかなり知りません。 – user6738171

関連する問題