我制作的网站需要显示WordPress帖子信息( Headers ,标签,缩略图) . 从已发布的帖子获取此信息的PHP代码可在我的localhost上运行,并且可以正确显示帖子数据 .
我刚刚将该站点上传到我的主机服务器,将WP设置配置为与我的localhost WP安装相同,并且99%的站点按预期工作,但不显示帖子的信息 .
目前在网站上有3个测试帖子 . 我可以通过DOM检查器看到3个文章标签,因此用于检索帖子的WP循环工作正常 . 但是,在每个文章标记中,应包含数据的entry-content标记为空 .
所有其他PHP代码正在执行,但这个小块 . 有人对解决这个问题有一些建议吗?
这是图像(显示文章标签的黄色突出显示):
第一个直播服务器,空div:
在本地主机的第二个,数据显示正常:
这是相关代码:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php
$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
if ( $images ) :
$total_images = count( $images );
$image = array_shift( $images );
$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
?>
并且在该代码下面是显示缩略图的PHP ...(省略了其他帖子数据的 Headers 代码,例如title) . 网站上没有显示任何数据:
<figure class="gallery-thumb">
<span class="image-wrapper">
<?php echo $image_img_tag; ?>
所有这些div和图形标签都在页面下方正确关闭 .
谢谢你的帮助 .
1 回答
看起来
$images
变量为空(或假),if
语句不会在<figure>
之前结束 .图片仅在上传时附加到帖子 . 如果您使用媒体中心的图像作为精选图片,则不会将其附加到帖子中 . 您可以通过使用
get_post_meta( $post->ID, 'featured_image' )
获取元字段来检索此图像,或者如果您使用特色图像,也可以使用get_the_post_thumbnail( $post->ID )
.