获取主题目录路径 get_template_directory_uri() 范例
获取首页地址
home_url() 或者 get_home_url() 范例 home_url();或者 get_home_url(); Output: http://www.example.com home_url( '/' ); Output: http://www.example.com/
home_url( $path = '/', $scheme = https ); Output: https://www.example.com/
home_url( $path = 'example', $scheme = relative ); Output: /example
获取样式表所在目录 get_stylesheet_uri()
获取当前文章的作者名称 the_author(); get_the_author();
获取作者信息 the_author_meta() 范例 echo the_author_meta('description'); 作者描述 get_the_author_meta( 'user_email'); 作者Email 作者信息可用的变量 user_login user_pass user_nicename user_email user_url user_registered user_activation_key user_status display_name nickname first_name last_name description jabber aim yim user_level user_firstname user_lastname user_description rich_editing comment_shortcuts admin_color plugins_per_page plugins_last_view ID
获取Gravatar头像: get_avatar(id或email,尺寸,默认,图像alt,数组); 输出当前作者头像 长宽32 echo get_avatar( get_the_author_meta( 'ID' ), 32 ); echo get_avatar( get_the_author_meta('user_email'), 48 );
获取头像URL get_avatar_url();
判断是否有缩略图 has_post_thumbnail(); 范例 判断有无缩略图 有则输出 无则用一张静态图代替。
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '
';
}
显示缩略图 the_post_thumbnail();
the_post_thumbnail(); // 无参数
the_post_thumbnail( 'thumbnail' ); // 缩略图 (default 150px x 150px max) the_post_thumbnail( 'medium' ); // 中尺寸 (default 300px x 300px max) the_post_thumbnail( 'large' ); // 大尺寸 (default 640px x 640px max) the_post_thumbnail( 'full' ); // 原尺寸 (original size uploaded)
the_post_thumbnail( array(100, 100) ); // 其他尺寸
注册新的尺寸要使用: add_image_size(). 设置默认的缩略图尺寸 使用: set_post_thumbnail_size().
自定义缩略图Class 和标题 the_post_thumbnail('post-thumbnail', ['class' => 'img-responsive responsive--full', 'title' => 'Feature image']);
获取缩略图的图片地址 get_the_post_thumbnail_url();
当前文章的固定连接 the_permalink();
get_permalink();
显示当前文章的锚点链接 permalink_anchor();
获取当前文章的标题
the_title(); get_the_title();
获取文章分类 the_category(); get_category();
分类并以逗号隔开 the_category(', ');
获取标签 the_tags(); 以井号开头显示标签 the_tags('#', ' #', '');
时间日期 the_time(); the_time('Y年n月d日'); get_the_time();
人类时间(时间差) human_time_diff(); human_time_diff( $from, $to ); 发布时间与当前时间差,按天
摘要 the_excerpt();
博客信息 bloginfo(); bloginfo( 'name' ); //显示博客名称 可替换的参数
admin_email = [email protected] atom_url = http://www.example.com/home/feed/atom charset = UTF-8 comments_atom_url = http://www.example.com/home/comments/feed/atom comments_rss2_url = http://www.example.com/home/comments/feed description = Just another WordPress blog home = http://www.example.com/home (DEPRECATED! use url option instead) html_type = text/html language = en-US name = Testpilot pingback_url = http://www.example.com/home/wp/xmlrpc.php rdf_url = http://www.example.com/home/feed/rdf rss2_url = http://www.example.com/home/feed rss_url = http://www.example.com/home/feed/rss siteurl = http://www.example.com/home (DEPRECATED! use url option instead) stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo stylesheet_url = http://www.example.com/home/wp/wp-content/themes/largo/style.css template_directory = http://www.example.com/home/wp/wp-content/themes/largo template_url = http://www.example.com/home/wp/wp-content/themes/largo text_direction = ltr url = http://www.example.com/home version = 3.5 wpurl = http://www.example.com/home/wp
获取文章类型 get_post_format();
获取文章类型列表链接 get_post_format_link(); get_post_format_slugs() 别名
