【发布时间】:2012-07-02 18:52:45
【问题描述】:
如何在 wordpress 中通过 ID 获取自定义帖子并显示其缩略图、标题和内容?这是我正在使用的,但内容没有混乱。
<div class="left-cont1">
<div class="left-cont1-text">
<?php
query_posts('post_id=790&post_type=homepage');
while (have_posts()): the_post();
?>
<h1><?php the_title(); ?></h1>
<div class="cont1-border"></div>
<p><?php echo(types_render_field("homepage-content", array("raw"=>"true"))); ?></p>
<h2><a href="<?php the_permalink();?>/more/"><?php echo(types_render_field("homepage-urltitle", array("raw"=>"true"))); ?></a></h2>
</div>
<div class="left-cont1-image1"><?php echo get_the_post_thumbnail($page->ID, 'home-circle'); ?></div>
<?php endwhile;?>
</div>
谢谢
【问题讨论】:
-
“内容乱七八糟”是什么意思?是拉错了帖子,什么都没有,还是……?
-
嗨,@Andrew。一切都在重复,就像它在一个页面中多次显示相同的缩略图、帖子等一样。我只想显示四个帖子。
-
在您发布的代码中,您仅拉入 ID=790 的单个帖子。这意味着此后的任何循环都只会拉入该帖子。此外,
$page->ID不会获得当前在循环中的帖子的 ID。如果需要,请使用get_the_ID() -
嗨@Andrew,非常感谢您的回复。我对 WordPress 和 php 世界很陌生。我想在一个单独的 div 中显示 4 个不同的帖子。每个 div 包含特定帖子的标题、缩略图和内容。我的帖子 ID 为 790、771、810 和 805。有简单的方法吗?