首页 视频课程 WordPress开发文档文章循环输出与重置 文章循环

文章循环

2020-04-03 / 4145阅

本视频需要登录以后才能播放

登录

WordPress的函数中,the开头的基本都是直接输出内容,get开头是获取内容。

纯PHP输出文章

while(have_posts()):the_post();
       echo '<a href="'.get_the_permalink().'">'.get_the_title().'</a><br/>';
       $i++;
endwhile; 

PHP与HTML混合输出文章

<?php while(have_posts()):the_post(); ?>
       <a href="<?php the_permalink();?>"><?php the_title();?></a><br/>';
<?php endwhile;?> 

不同页面使用以上默认循环得到的结果是不同的。

  • 首页会输出所有分类下面的最新文章
  • 分类页会显示当前分类下的文章
  • 归档页会显示符合当前归档的文章
  • 内容页只会显示当前ID的文章

循环中常用的函数

直接输出获取值作用备注
the_title()get_the_title()文章标题
the_excerpt()get_the_excerpt()文章摘要
the_ID()get_the_ID()文章ID
the_content()get_the_content()文章内容 只能在循环中使用
the_permalink() get_ the_permalink() 文章链接
the_category()get_the_category()文章分类
the_author() get_the_author() 文章作者只能在循环中使用
edit_post_link() get_edit_post_link() 编辑链接
the_tags()get_the_tags()文章标签
the_time()get_the_time()文章时间
the_date()get_the_date()文章日期
the_modified_author ()get_the_modified_author()修改作者
the_modified_time()get_the_modified_date()修改时间
the_modified_date()get_the_modified_date()修改日期
next_image_link()
next_post_link() get_next_post_link()
next_posts_link() get_ next_posts_link()
previous_post_link()previous_post_link()
previous_posts_link()get_previous_posts_link()

暂时给大家介绍这些函数,以后用到的地方再给大家介绍其他的

阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228

大家谈论
    我的见解
    目录