/*** Iterate the post index in the loop.** @since 1.5.0** @global WP_Query $wp_query WordPress Query object.*/functionthe_post(){global$wp_query;// 声明全局变量 $wp_query,以便在函数中访问当前查询对象if(!isset($wp_query)){//
经常会在网站首页调用文章的时候,需要有图片一起展示,wordpress本身有缩略图功能,可以通过has_post_thumbnail来判断是否有缩略图, the_post_thumbnail来调用。...但是wordpress的缩略图需要手动设置,并不能自动获取文章内的图片来作为缩略图,通过以下方法完成缩略图自动设置。...自动设置缩略图的逻辑:如果设...
WordPress的have_posts() 默认是一个全局函数。 have_posts函数被调用时实际上是调用全局变量$wp_query->have_posts()成员函数,来简单检查一个全局数组(array)变量$posts的一个循环计数器,以确认是否还有post,如果有返回true(1),如果没有返回false(0)。 the_post()解析: the_post()函数则调用$wp_query->the...
the_post_thumbnail(‘homepage-thumb’); 显示220*180的缩略图 在分类页面调用 1 the_post_thumbnail(‘category-thumb’); 则显示200*200的缩略图。 定义缩略图的样式 首先我们先来看一下the_post_thumbnail函数输出的html是什么样的 1 2 由此可以看出,我们可以用css定义类attachment-thumbnail的样式就可以了。
have_posts()和the_post()。have_posts()解析:WordPress的have_posts() 默认是一个全局函数。have_posts函数被调用时实际上是调用全局变量$wp_query->have_posts()成员函数,来简单检查一个全局数组(array)变量$posts的一个循环计数器,以确认是否还有post,如果有返回true(1),如果没有返回false(0)。
(int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`. Required: 否 Default: null (string|int[]) $size Optional. Registered image size to retrieve the source for or a flat array of height and width dimensions. Default 'post-thumbnail'. Required: 否...
显示当前文章的缩略图(Post Thumbnail)。 这个模板函数必须使用在主循环中,如果要获取任意文章的缩略图,使用 [function title=get_the_post_thumbnail]get_the_post_thumbnail($id, $size, $attr )[/function] 函数代替。
the_post()解析: the_post()函数则调用$wp_query->the_post()成员函数前移循环计数器,并且创建一个全局变量$post(不是$posts),把当前的post的所有信息都填进这个$post变量中,以备接下来使用。 简单的使用可以通过函数来直接执行,如the_content()直接显式post的内容,the_title()显式帖子的标题,the_time()显...
int targetSize = 0,WordPress 已经提供原生的获取特色图片地址的函数:get_the_post_thumbnail_url。通...
*(where___isthepostformat)andthatwillbeusedinstead. */ get_template_part('content',get_post_format()); endwhile; //Previous/nextpostnavigation. twentyfourteen_paging_nav(); else: //Ifnocontent,includethe"Nopostsfound"template. get_template_part('content','none'); ...