gpt4 book ai didi

php - 如何在 html/php 页面中显示来自 wordpress 博客的帖子图像

转载 作者:行者123 更新时间:2023-12-04 07:16:13 26 4
gpt4 key购买 nike

下面是我的代码,用于在 html/php 页面中显示博客的最新帖子

    <div class="row">
<?php

include('blog/wp-load.php');
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 3,
'post_type' => 'post',
'post_status' => 'publish'
));
foreach($recent_posts as $post) {
echo '<div class="col-lg-4">';
echo '<div class="blog-entry">';
echo '<a href="', get_permalink($post['ID']), '" style="background-image: url(images/BlogImg.png);"></a>';
echo '<div class="text">';
echo '<div class="meta">';
echo '<div><span class="fa fa-calendar-alt"></span>', $post['post_date'], '</a></div>';
echo '<div><span class="fa fa-user"></span>', $post['post_author'], '</div>';
echo '<div><span class="fa fa-comments meta-chat"></span>', $post['comment_count'], '</div>';
echo '</div>';
echo '<div class="desc">';
echo '<h3 class="heading"><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></h3>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}

?>
</div>
如何使用 background-image: url(images/BlogImg.png); 显示帖子图像
代替 images/BlogImg.png我想发布相应博客文章的图片网址。
谁能告诉我我怎样才能做到这一点?

最佳答案

使用以下几行:

<div class="row">
<?PHP

include('blog/wp-load.php');
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 3,
'post_type' => 'post',
'post_status' => 'publish'
));
foreach($recent_posts as $post) {
$imgurl = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' );

echo '<div class="col-lg-4">
<div class="blog-entry">
<a href="'. get_permalink($post['ID']). '" style="background-image: url('.$imgurl.');"></a>
<div class="text">
<div class="meta">
<div><span class="fa fa-calendar-alt"></span>' . $post['post_date'] . '</a></div>
<div><span class="fa fa-user"></span>'. $post['post_author'] . '</div>
<div><span class="fa fa-comments meta-chat"></span>' . $post['comment_count'] . '</div>'
</div>
<div class="desc">
<h3 class="heading"><a href="' . get_permalink($post['ID']) . '">' . $post['post_title'] . '</a></h3>
</div>
</div>
</div>
</div>';
}

?>
</div>

关于php - 如何在 html/php 页面中显示来自 wordpress 博客的帖子图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68741619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com