php - Wordpress - 无法获取我页面的内容。收到关于 post-template.php 的错误
问题描述
我正在编辑我的 page.php 文件并尝试在每个页面上显示特定的页面内容。我可以看到标题,但我收到错误的内容。
这是我看到的错误:
警告:count():参数必须是在 C:\xampp\htdocs\wordpress\wp-includes\post-template.php 第 310 行实现 Countable 的数组或对象
在搜索之后,人们说 PHP v. 7.2 有问题。我正在使用 PHP v. 7.3。人们还说他们应该停用任何插件,但我没有安装任何人。
这是page.php文件
<?php
/**
* Template Name: Mallsida
*/
?>
<?php get_header(); ?>
<main role="main">
<section class="page-bg" id="post-<?php the_ID(); ?>">
<h1><?php single_post_title();?></h1>
</section>
<section class="page-content">
<div class="container">
<h2><?php single_post_title();?></h2>
<p><?php the_content()?></p>
</div>
</section>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
解决方案
在您的情况下,问题是因为您没有使用默认的 wordpress 循环函数,然后调用 the_content 请参见下面的代码:
<?php get_header(); ?>
<main role="main">
<section class="page-bg" id="post-<?php the_ID(); ?>">
<h1><?php single_post_title();?></h1>
</section>
<section class="page-content">
<div class="container">
<?php
//modified here--------
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_content();
}
}
//finishing modification
?>
</div>
</section>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
另一个注意事项:
不要使用
the_content周围的标签仅使用块标签,如div、section 等
推荐阅读
- c - 你知道为什么有些 C 指令可以被完全忽略吗?
- php - Laravel - 如何正确地将按钮路由到控制器功能?
- javascript - 检查控件中的古腾堡媒体上传
- php - 单击更新帖子按钮后,我收到 MethodNotAllowedHttpException 错误
- python - 使用 Folium geo_json 读取 JSON 文件时出错
- python - 如何在 python 中通过 SSH 注入命令?
- excel - VBA InsertRow 问题
- ajax - 我怎样才能等到变量可用?
- python - 使用列标题和行值创建新列
- cs50 - 每个 if 公式的输出,CS50 问题集学分