我是Wordpress的新手,我试图在我的php文件中发布所有帖子。
global $post;
$args = array('posts_per_page' => 10,
'order'=> 'ASC',
'orderby' => 'date'
);
$postslist = get_posts( $args );
if($postslist) {
foreach ( $postslist as $post ) :
setup_postdata( $post );
?>
<p><?php the_date(); ?></p>
<p><?php the_title(); ?></p>
<p><?php the_excerpt(); ?></p>
<?php the_attachment_link($post->ID, false); ?>
<?php
endforeach;
}
wp_reset_postdata();
?>
标题,日期和描述确实出来但不是附件。我需要显示所有帖子以及没有附件的帖子。现在它说&#34;缺少附件&#34;。
提前致谢:-)
答案 0 :(得分:0)
您可以尝试这样......
<?php
$args = array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>10, 'orderby'=>'date', 'order'=>'ASC');
$post_list = get_posts($args);
foreach($post_list as $post) {
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<p><?php the_time('Y/m/d'); ?></p>
<p><?php echo $post->post_title;?></p>
<p><?php echo $post->post_excerpt;?></p>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img src="<?php echo $url ;?>" />
<?php } ?>