php - 如何在wordpress中获取页面内容?
问题描述
我正在建立一个名为 About us 的页面,并且永久链接为: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( ); ?>
解决方案
在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;
?>
推荐阅读
- c# - 2020 年 2 月微软更新后 COM+ 异常“类未注册”
- python - Python 中的 Flask 错误:“无法导入 webapp”
- graphql - 在 graphql 中查询 Prismic Content-Realtionship 字段组时,文档字段返回 null
- ios - UIView 作为@EnvironmentObject 的订阅者
- javascript - 按下 button.addEventListener 后如何让这个 div 元素出现?
- neural-network - 在我的情况下我应该考虑什么来减少 val_loss?
- firebase - Firebase 托管自定义域在尝试添加 www 重定向时突然停止工作
- reactjs - 使用标题和内容将帖子分享到 Facebook
- php - 未从 Moodle 中的本地插件返回的警告消息
- php - 将php数组的输出排序为元素