【发布时间】:2020-11-12 21:19:34
【问题描述】:
我正在尝试将 about 页面的内容放在标题的 div 中,模板部分位于文件夹 template-parts/content-about.php
在标题上的代码是:
<div id="slideOut">
<div class="slideout-content">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'about' );
endwhile; // End of the loop.
?>
<?php include 'content-about.php'; ?>
</div><!-- .slideout-content -->
</div>
content-about.php 看起来像这样:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php
the_content();
wp_link_pages(
array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'about' ),
'after' => '</div>',
)
);
?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
问题是在 div 上显示与当前页面相同的内容,例如,如果我位于主页上,它只显示 div 内的主页内容,而它应该始终显示关于页面。 为什么不工作? 谢谢
【问题讨论】:
-
因为您的
content-about.php中没有任何内容告诉它从该页面获取内容。如果你查看你的文件,你使用的是the_content()。由于它在循环中,因此它将从您所在的任何页面获取内容。您可以使用get_the_content()并将关于页面id传递给该函数。仅仅因为文件被命名为content-about并不意味着它会从该文件中获取内容。 -
谢谢你能给我举个例子吗,我是wordpress这部分的新手。
-
当然。我会添加一个答案。