首页 文章

缺少附件 . 从Wordpress获取所有帖子不显示附件

提问于
浏览
1

我是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();
?>

Headers ,日期和描述确实出来了但不是附件 . 我需要显示所有帖子以及没有附件的帖子 . 现在它说“缺少附件” .

提前致谢 :-)

1 回答

  • 0

    You can try like this...

    <?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 } ?>
    

相关问题