【发布时间】:2014-07-21 11:19:35
【问题描述】:
我是 wordpress 和 wordpress 循环的新手。我试图理解循环但没有任何成功。贝尔和我一起,我会尽力解释我不明白的......
我使用了一个名为“graphy”的模板。当我创建一个“页面”时,可以选择创建一个没有侧边栏的页面,模板称为“nosidebar.php”,这是它的代码:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
1- 为什么这个模板包含一个循环?它只显示没有侧栏的单个页面内容!显然它不是循环浏览帖子并显示它们!
我尝试创建自己的模板页面,该页面仅用于首页,这就是我想出的
<?php
/**
* Template Name: Main_Page
* Description: A page template without sidebar.
*
* @package Graphy
*/
get_header();
?>
<!--<div id="primary" class="content-area">-->
<!--<main id="main" class="site-main" role="main">-->
<div id="main_content">
<?php
the_content(); // the content
?>
</div>
<!--</main> #main -->
<!--</div> #primary -->
<?php get_footer(); ?>
但是,当我安装 this plugin 时,它用于将小部件插入页面和帖子 使用 main_page 没有显示小部件,但是当我切换到“无侧边栏页面”时它起作用了。 然后我将循环复制到我的主页中并且它起作用了。
2- 这个循环使插件工作的秘密是什么,而只调用<?php the_content() ?> 不能?!显然,这个循环除了互联网上 90% 的帖子所解释的内容之外,还做了一些其他的事情。
【问题讨论】:
-
如果对你来说一切都一样,我会继续穿衣服谢谢
-
请问? ,我什么都不懂!
-
@user574632 我改了 :) 谢谢。