[英]Missing Attachment. Get all posts from Wordpress do not show the attachment
我是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();
?>
確實會顯示標題,日期和描述,但不會顯示附件。 我需要顯示所有帖子以及沒有附件的帖子。 現在它說“缺少附件”。
提前致謝 :-)
你可以這樣嘗試...
<?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 } ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.