无法在WordPress中获取页面内容

时间:2018-08-02 13:29:08

标签: php wordpress

当我在the_content()上使用page-about-us时,无法从WordPress获取关于我们页面的内容。

我只有以下警告

  

警告:count():参数必须是数组或对象,   实现Countable in   D:\ xampp \ htdocs \ megacity \ wp-includes \ post-template.php第284行

我怎么了?请帮我找到这个。

enter image description here

我只使用了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();
 ?>

1 个答案:

答案 0 :(得分:1)

这是由插件或主题在循环the_content()之外调用$pages = null引起的。如果尝试计算不可数类型,这将导致php 7.2抛出错误。

在这种情况下,您必须将the_content()函数放在主循环中,如下所示:

if ( have_posts() ) {
    while ( have_posts() ) { the_post();

        the_content();

    }
}