wp二次开发入门
主循环
The Loop should be placed in the Theme’s index.php and in any other Templates used to display post information.
Be sure to include the call for the header template at the top of your Theme’s templates. If you are using The Loop inside your own design (and your own design is not a template), set WP_USE_THEMES to false:
1 | define( 'WP_USE_THEMES', false ); get_header(); |
The loop starts here:
1 | if ( have_posts() ) : while ( have_posts() ) : the_post(); |
and ends here:
1 | endwhile; else : |
This is using PHP’s alternative syntax for control structures, and could also be expressed as:
1 |
|
元数据
API
| 添加元数据 | 获得元数据 | 更新元数据 | 删除元数据 | |
|---|---|---|---|---|
| 文章 | add_post_meta() |
get_post_meta() |
update_post_meta() |
delete_post_meta() |
| 用户 | add_user_meta() |
get_user_meta() |
update_user_meta() |
delete_user_meta() |
| 评论 | add_comment_meta() |
get_comment_meta() |
update_comment_meta() |
delete_comment_meta() |
| 参数 | $post_id, $meta_key, $meta_value, $unique (可选的) |
$post_id, $meta_key, $single (可选的) |
$post_id, $meta_key, $meta_value, $prev_value (可选的) |
$post_id, $meta_key, $meta_value (可选的) |
postmeta
语法:
1 |
|
此方法返回一个数组,如果single设置为true则返回数组中的第一项
postmeta元数据储存在数据库中的wp_postmeta中
(mixed) Single metadata value, or array of values. False if there’s a problem with the parameters passed to the function.
常用函数
edit_post_link('Edit', ' | ', '')
管理员编辑the_category(',')
分类,使用,分隔分页导航
1
2
3
4
5the_posts_pagination(array(
'mid_size' => 5,
'prev_text' => __('上一页'),
'next_text' => __('下一页'),
));wp_list_cats()
调用分类链接列表
署名-非商业性使用本文采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ZEKALRYN'S BLOG!
评论
