Php 如何使用post id显示特定的post
我试图通过使用post ID来显示两个特定的post。但是我不知道使用什么代码来调用post ID。有人能帮我吗 /////////////////////////////// //////////////////////////////Php 如何使用post id显示特定的post,php,html,wordpress,post,custom-post-type,Php,Html,Wordpress,Post,Custom Post Type,我试图通过使用post ID来显示两个特定的post。但是我不知道使用什么代码来调用post ID。有人能帮我吗 /////////////////////////////// ////////////////////////////// 流行的 流行的 最新食品使用get_post()获取特定帖子 get_post() 例如: <?php $postData = get_post( $id, $output, $filter ); echo "<pre>"; p
流行的
流行的
最新食品
使用get_post()获取特定帖子
get_post()
例如:
<?php $postData = get_post( $id, $output, $filter );
echo "<pre>";
print_r($postData);
?>
如何有效地将此代码添加到上面的代码中?查看此链接查看功能图片/标题。是否喜欢我原始答案中的更新代码?抱歉,我还不是php的高手,所以我不太知道如何编写。代码不起作用,它只生成一个空白页。请确定您的帖子类型并检查var_dump($query)的put;还有var_dump($anotherQuery)。
<?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>
?>