我想创建一个模板,用于选择要在WordPress页面上显示的5篇特定帖子。
基本上,我必须能够查询5个确切的帖子,以显示在Wordpress页面上,使用WP页面模板和自定义字段来选择准确的5个帖子ID。
编辑:我有这个代码感谢这个网站。但现在我需要能够通过自定义字段添加页面id数组。这能做到吗?
编辑2:实际上代码并没有显示数组中的帖子,而是显示主页上的最新帖子。嗯,嗯。
<?php
$post_id = array(483,454,376);
$posts = get_posts( $post_id);
foreach( $posts as $post ) :
setup_postdata($post); ?>
// you can call use post data inside here like
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<a class="thumb" href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, \'thumbnail\', \'alt="\' . $post->post_title . \'" class="hthumb"\'); ?></a><?php the_excerpt(45); ?><a href="<?php the_permalink(); ?>" class="more">Read More..</a><div style="clear:both;"></div>
<?php endforeach; ?>