php - Wordpress 网站只显示最新帖子
问题描述
我的 WordPress 网站是一个编码网站,最近我在主页上创建了一个新块来处理来自我的一个类别的所有最新帖子。但问题是第一个或最新的帖子在页面上返回一个空白区域。我的页面上有其他块可以执行此操作,但这个问题不会发生在他们身上,我只复制了他们的代码。我试图更改帖子的类别,它适用于其他人。只有新创建的类别块会产生此问题。我已经检查了空帖子的元素,它不会像下一个帖子那样返回 href 块。
<div style="border: 2px solid #23429a; width: 210px; float: left; border-top-left-radius:3px; border-top-right-radius:3px;" >
<!--TITLE-->
<div style="background-color: #23429a; color: white; padding: 6.3px 6px; font-size: 16px;">
<b>My category</b>
</div>
<!--CONTENT-->
<div style="height: 190px; margin-top: -8px; margin-bottom: -8px;">
<div class="test" style="margin: 10px 5px">
<?php $the_thirdquery = new WP_Query(array('cat' => 32, 'posts_per_page' => 4)); ?>
<table style="font-size: 14px; margin: auto;">
<tbody>
<?php while ($the_thirdquery -> have_posts()) : $the_thirdquery -> the_post(); ?>
<tr style="height: 35px;">
<td width="30px">
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;"><?php the_time('m/d'); ?></font>
</font>
</td>
<td style="padding-left:20px;">
<div style="font-size: 13px; width: 140px;">
<?php if ($custom_post_type == "Clinic") { ?>
<a href= "<?php the_permalink(); ?>" target="_blank"> <?php the_title(); ?></a>
<?php } ?>
</div>
</td>
<!-- <td style="text-align: right; padding-left:25px;" width="20px">
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;"> -->
<?php $custom_post_type = get_post_meta($post->ID, 'custom_element_grid_class_meta_box', true);?>
<!-- <?php #echo $custom_post_type;?> -->
<!-- </font>
</font>
</td> -->
</tr>
<?php
endwhile;
?>
</tbody>
</table>
<?php
wp_reset_postdata();
?>
</div>
</div>
</div>
对不起我的代码。
但是还有其他人经历过这种情况吗?
解决方案
如果您遇到$the_thirdquery
了几行的问题,那么我认为您在数组中没有足够的 args 来完成您想要从WP_Query
. 此外,我不确定$custom_post_type
调用来自何处或被用作在if()
块之后声明的调用。如果它是自定义帖子类型,请将其添加到$args
. 试试这个,看看它是怎么回事,然后评论你的结果。
$args = array(
'cat' => 32,
'posts_per_page' => 4,
'post_type' => 'clinic',
'orderby' => 'date',
'order' => 'DESC',
);
$query = new WP_Query($args);
if($query->have_posts()):while($query->have_posts()):$query->the_post(); {
// add your code here for the query.
}
推荐阅读
- reactjs - Webpack:如何检查自定义 index.js 文件是否存在并加载它
- java - 使用 ant 替换字符串中的子字符串的正则表达式
- java - 要求在我只使用 POST 方法的 servlet 中使用 GET
- python - Python 程序未按预期工作
- c++ - C++ 从函数返回无符号字节
- c - 使用 strtok 将长字符串拆分为较短字符串时出错
- node.js - compser -v 不显示版本,并且在 ubuntu 16.04 上找不到 composer-playground 命令
- swift - enumerateChildNodes 是否对孙子进行排序?
- c# - 如何在 .NET Core 中使用 HttpClientHandler 和 HttpClientFactory
- c++ - 如何用 C++ 打开和关闭 DVD-RW?