【问题标题】:Missing Attachment. Get all posts from Wordpress do not show the attachment缺少附件。从 Wordpress 获取所有帖子不显示附件
【发布时间】:2018-02-16 10:25:32
【问题描述】:

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

标题、日期和描述会出现,但附件不会出现。我需要显示所有帖子以及没有附件的帖子。现在它说“缺少附件”。

在此先感谢 :-)

【问题讨论】:

  • "Missing Attachment" 是指张贴缩略图吧?
  • 附件是帖子中的媒体。 Wordpress 中的文本如下所示:

    some text.

    192.168.87.200/wp-content/uploads/2018/02/treeimage.jpg" alt="" width="480" height="640" />

标签: php wordpress wordpress-theming


【解决方案1】:

你可以这样试试……

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

【讨论】:

  • 我刚试过。文本:“缺少附件”现在消失了,但附件仍未显示?
  • 现在我只是从帖子中获取标题,而不是描述、附件或日期:-S
  • 现在我正在获取页面的日期和标题:-S 当我在 google 中查看检查工具时,它会生成 但 src 属性是未知的。跨度>
  • 所以你的帖子没有特色图片。就是这样
  • 不,它在文本中有图像。我刚刚将图像添加为特色图像,然后您的代码正在运行,但图像必须是特色图像才能在 Wordpress 中显示。用户仅添加媒体还不够?
猜你喜欢
  • 1970-01-01
  • 2013-09-21
  • 2013-01-20
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
  • 2014-09-05
  • 1970-01-01
相关资源
最近更新 更多