2017-01-16 65 views
0

我想通过帖子ID显示两个帖子。但是我找不出用什么代码来调用帖子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

相关问题