wordpress建站过程4——index.php

 1 <?php
 2 
 3 
 4 get_header(); ?>
 5 
 6     <div id="primary" class="content-area col-md-9">
 7         <main id="main" class="site-main" role="main">
 8 
 9         <?php if ( have_posts() ) : ?>
10 
11             <?php /* Start the Loop */ ?>
12             <?php while ( have_posts() ) : the_post(); ?>
13 
14                 <?php
15                     /* Include the Post-Format-specific template for the content.
16                      * If you want to override this in a child theme, then include a file
17                      * called content-___.php (where ___ is the Post Format name) and that will be used instead.
18                      */
19                     get_template_part( 'content', get_post_format() );
20                 ?>
21 
22             <?php endwhile; ?>
23 
24             <?php blain_pagination(); ?>
25 
26         <?php else : ?>
27 
28             <?php get_template_part( 'no-results', 'index' ); ?>
29 
30         <?php endif; ?>
31 
32         </main><!-- #main -->
33     </div><!-- #primary -->
34 
35 <?php get_sidebar(); ?>
36 <?php get_footer(); ?>

以上是一个index.php

中间有几个重要的函数:

get_header()————调用header.php,该函数和下面几个一样是wordpress提供的函数。

get_footer()————调用footer.php

get_sidebar()————调用sidebar.php

get_template_part('a','b')——调用其他文件,如果存在a-b.php文件,将其调用,没有就只调用a.php

index.php的内容大多都是调用,将其他php内容调用组合起来,当然,你要直接在其中写代码也可以。

 

have_posts() ) : the_post();
循环文章,如果存在,则一章章的读取,每一次读取都会将这个while整个部分循环一遍。这个是用于循环输出文章的标题等简单信息的。
这一段的意思是循环读取文章,每读取了一次,就加载content.php或content-n.php文件(后面的函数用于判断文章类型,除了系统设定的之外,还能在functions.php中添加几个)
而这个content.php就是如何展示文章的文件,是否要缩略图,标题的大小和位置等等都会在这里规定,例如:

这样。当然除了这种类似贴吧的首页之外,也能放其他东西,例如视频什么的,不一定非要调用文章部分内容。

 

转载于:https://www.cnblogs.com/thestudy/p/6278875.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值