如何在wordpress中获取页面内容?

时间:2018-06-11 03:56:18

标签: php wordpress

我正在构建一个名为“关于我们”的页面,其永久链接为:http://virtual1.com/index.php/about-us

我也查询了获取页面内容但我得到的内容是空白的(它没有显示上次修改页面的日期,也没有显示作者,内容段落) 这是代码:

<?php 
$args = array(
    'posts_per_page'   => -1,
    'post_type'        => 'page',
    'slug' => 'about-us'
);
$the_query = new WP_Query( $args );

?>
<?php get_header(  ); ?>
<?php
while ( $the_query->have_posts() ): $the_query->the_post();?>
<!--Main body-->
<div id="content">
      <div class="container">
          <div class="row">
            <div class="content-inner">
                            <!-- Left sidebar -->
             <div id="component" class="col-sm-12">
             <main role="main">

              <div id="system-message-container">
              </div>

<article class="page-item page-item__blog page-item__" itemscope="">
    <div class="item_info">
    <dl class="item_info_dl">
        <dt class="article-info-term">
        </dt>
            //Get the date last modified of the page
            <dd>
                <time datetime="2018-02-26 10:14" class="item_published">
                    <?php get_the_modified_date(  ); ?>     
                </time>
            </dd>
            <dd>
            //Get the author of the page
            <address class="item_createdby">
            <?php get_the_author(  ); ?>            
            </address>
        </dd>
    </dl>
</div>

//Get the paragraph in the page here
<div class="item_fulltext">
    <p>
        <?php echo $content?>
    </p>    
</div>
<!--End loop-->
<?php endwhile; ?>
<!--End of main body-->
<?php get_footer(  ); ?>

1 个答案:

答案 0 :(得分:0)

page.php 中编写代码,代替 $ content 功能 the_content()将完成您的工作。

<?php 
      get_header(); 
      $page_id=get_the_ID();
      $the_query = new WP_Query( array( 'p' => $page_id ) );

      while ( $the_query->have_posts() ): $the_query->the_post();
?>
       <div id="content">
      <div class="container">
          <div class="row">
            <div class="content-inner">
                            <!-- Left sidebar -->
             <div id="component" class="col-sm-12">
             <main role="main">

              <div id="system-message-container">
              </div>

<article class="page-item page-item__blog page-item__" itemscope="">
    <div class="item_info">
    <dl class="item_info_dl">
        <dt class="article-info-term">
        </dt>
            //Get the date last modified of the page
            <dd>
                <time datetime="2018-02-26 10:14" class="item_published">
                    <?php get_the_modified_date(); ?>     
                </time>
            </dd>
            <dd>
            //Get the author of the page
            <address class="item_createdby">
            <?php get_the_author(); ?>            
            </address>
        </dd>
    </dl>
</div>

//Get the paragraph in the page here
<div class="item_fulltext">
    <p>
        <?php the_content(); ?>
    </p>    
</div>
<?php 
      endwhile;
?>