为什么 the_title() 在我调用循环之前返回 post 的标题?
Why the_title() is returning me the title of the post before I call the loop?
我是 wordpress 的完全菜鸟,我正在学习 wordpress 的主题开发。
更多的是出于科学兴趣而不是问题。
我正在为我的主题制作一个 single.php 页面,我有这个并且正在工作。
<?php get_header();?>
<h2 class="mb-4"><?php the_title();?></h2>
<div class="row">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_content();
}
}
?>
</div>
<?php
get_footer(); ?>
我想知道为什么会这样。为什么 the_title() 在我调用循环之前给我 post 的标题。如果我做 var_dump(the_post());在循环之前我没有得到任何东西。同样,如果我在循环之前调用 the_content() 我什么也得不到。我之前正在打印 wp_nav_menu() 这与它有什么关系吗?
wordPress 是一个内容管理系统,其设计和开发的方式是 single.php 是为了获取 post 的数据。所以 the_title 不需要在循环内部。有关详细信息,我建议您阅读以下文档:
https://developer.wordpress.org/themes/basics/template-files/
我是 wordpress 的完全菜鸟,我正在学习 wordpress 的主题开发。
更多的是出于科学兴趣而不是问题。
我正在为我的主题制作一个 single.php 页面,我有这个并且正在工作。
<?php get_header();?>
<h2 class="mb-4"><?php the_title();?></h2>
<div class="row">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_content();
}
}
?>
</div>
<?php
get_footer(); ?>
我想知道为什么会这样。为什么 the_title() 在我调用循环之前给我 post 的标题。如果我做 var_dump(the_post());在循环之前我没有得到任何东西。同样,如果我在循环之前调用 the_content() 我什么也得不到。我之前正在打印 wp_nav_menu() 这与它有什么关系吗?
wordPress 是一个内容管理系统,其设计和开发的方式是 single.php 是为了获取 post 的数据。所以 the_title 不需要在循环内部。有关详细信息,我建议您阅读以下文档:
https://developer.wordpress.org/themes/basics/template-files/