WordPress常用函数

使用方法说明:

点击下方代码即可自动复制

文章详情页常用调用函数:

输出文章ID:<?php the_ID(); ?>
获取文章ID:<?php get_the_ID(); ?>
文章作者:<?php the_author(); ?>
文章标题:<?php the_title(); ?>
文章链接:<?php the_permalink() ?>
ID获取文章链接:get_permalink($post_id)
文章时间:<?php the_time('Y-m-d'); ?>

首页常用:

网站名称:<?php bloginfo('name'); ?>

分类页常用函数:

分类别名:single_cat_title

文章自定义字段常见用法:

指定字段:<?php echo get_post_meta(get_the_ID(), 'remarks', true); ?>

用户字段常见用法:

指定字段:<?php echo get_user_meta($user_id, 'weixin_uid', true); ?>

获取主题目录路径

get_template_directory()获取当前主题的根目录URI路径,不包含“/wp-content/themes/”路径
get_template_directory_uri()获取当前主题的根目录URI路径,包含“/wp-content/themes/”路径

 

3. `get_stylesheet_directory()`:获取当前活动的子主题的根目录URI路径,不包含“/wp-content/themes/”路径。

4. `get_stylesheet_directory_uri()`:获取当前活动的子主题的根目录URI路径,包含“/wp-content/themes/”路径。

5. `get_theme_root()`:获取所有安装主题的根目录URI路径,不包含“/wp-content/themes/”路径。

6. `get_theme_roots()`:获取所有安装主题的根目录URI路径数组,不包含“/wp-content/themes/”路径。

7. `get_theme_file_path()`:根据主题中某个文件的相对路径,获取该文件的绝对路径。