无法在 WordPress 中获取页面内容
Posted
技术标签:
【中文标题】无法在 WordPress 中获取页面内容【英文标题】:Can't get page content in WordPress 【发布时间】:2019-01-10 07:15:25 【问题描述】:当我在 page-about-us
上使用 the_content()
时,我无法从 WordPress 获取关于我们页面的内容。
我只得到以下警告
警告:count():参数必须是数组或对象 实现可数 D:\xampp\htdocs\megacity\wp-includes\post-template.php 在第 284 行
我怎么了?请帮我找到这个。
我只使用了 unyson 插件。
<?php
get_header();
the_content();
global $megacity;
?>
<div class="container">
<div class="row">
<div class="aboutus-section">
<div class="col-md-4 left-block">
<h2 class="title block_maintitle">about us</h2>
<div class="description">
<p><?php echo $megacity['megacity-about-us-desc']; ?></p>
<div class="accordion_container">
<?php
// echo "<pre>";
// echo $megacity['megacity-about-us-dynamic-func'][0]['title'];
// echo "</pre>";
foreach( $megacity['megacity-about-us-dynamic-func'] as $key => $value )
?>
<div class="accordion_head"><span class="plusminus">+</span><?php echo $megacity['megacity-about-us-dynamic-func'][$key]['title']; ?></div>
<div class="accordion_body" style="display: none;">
<p>
<?php echo $megacity['megacity-about-us-dynamic-func'][$key]['description']; ?>
</p>
</div>
<?php
?>
<!-- <div class="accordion_head"><span class="plusminus">+</span>Health & Safety</div>
<div class="accordion_body" style="display: none;">
<p>
Megacity Township is a prosperous wing and journey of unique Devlopers into Construction & Real Estate Business. unique Devlopers has built its own empire and earned a reputation of being successful in various fields of businesses in India as well as Abroad.
</p>
</div>
<div class="accordion_head"><span class="plusminus">+</span>Drywall Technology</div>
<div class="accordion_body" style="display: none;">
<p>
Megacity Township is a prosperous wing and journey of unique Devlopers into Construction & Real Estate Business. unique Devlopers has built its own empire and earned a reputation of being successful in various fields of businesses in India as well as Abroad.
</p>
</div> -->
</div>
</div>
</div>
<div class="col-md-7 right-block">
<div class="vedio-block">
<img src="<?php echo $megacity['megacity-about-us-img']['url']; ?> " >
</div>
</div>
</div>
</div>
</div>
<?php
get_footer();
?>
【问题讨论】:
包括你的代码。 我添加了我的代码。请查看。 将the_content
放入while ( have_posts() ) : the_post();
并检查内容是否正在显示。
还是不行,伙计
奇怪 - 这个错误听起来像是,您的网站上没有页面?你是通过wordpress创建的吗?
【参考方案1】:
这是由在循环外调用the_content()
的插件或主题引起的,其中$pages = null
。如果尝试计算不可数类型,这将导致 php 7.2 抛出错误。
在您的情况下,您必须将 the_content()
函数放在主循环中,如下所示:
if ( have_posts() )
while ( have_posts() ) the_post();
the_content();
【讨论】:
我在代码中使用了 the_content()。你能再请一次吗?谢谢。以上是关于无法在 WordPress 中获取页面内容的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress REST API:如何在 WP REST API JSON 文件中获取“纯文字”内容?