zoukankan      html  css  js  c++  java
  • WordPress的have_posts()和the_post()用法解析

    原文地址:http://www.phpvar.com/archives/2316.html

    网上找到一篇介绍WordPress的have_posts()和the_post()用法解析的文章,觉得不错!

    在WordPress的index.php文章循环输出中,通常会有下面一段代码:

        <?php if (have_posts()) : ?>
    
        <?php while (have_posts()) : the_post(); ?>
    
        <!–PHP代码 –>
    
        <?php endwhile; ?>
    
        <?php endif; ?>

    这里有两个函数,have_posts()和the_post()。

    have_posts()解析:
    WordPress的have_posts() 默认是一个全局函数。

    have_posts函数被调用时实际上是调用全局变量$wp_query->have_posts()成员函数,来简单检查一个全局数组(array)变量$posts的一个循环计数器,以确认是否还有post,如果有返回true(1),如果没有返回false(0)。

    the_post()解析:

    the_post()函数则调用$wp_query->the_post()成员函数前移循环计数器,并且创建一个全局变量$post(不是$posts),把当前的post的所有信息都填进这个$post变量中,以备接下来使用。

    简单的使用可以通过函数来直接执行,如the_content()直接显式post的内容,the_title()显式帖子的标题,the_time()显示帖子的时间等WORDPRESS的Template Tags。

    高级应用或要定制应用则可以直接调用$post变量的成员。

  • 相关阅读:
    [Leetcode] Copy List with Random Pointer
    [Java] StringBuffer类
    [Leetcode] Wildcard Matching
    [Leetcode] Substring with Concatenation of All Words
    [Leetcode] Longest Palindromic Substring
    [Leetcode] Maximum Product Subarray
    [leetcode] Permutation Sequence
    [Leetcode] Simplify Path
    [Leetcode] Minimum Window Substring
    Owin asp.net 脱离 IIS
  • 原文地址:https://www.cnblogs.com/wangkongming/p/3551330.html
Copyright © 2011-2022 走看看