WordPress自带的条件标签使用说明

2019-02-19 19:00:25王冬梅

检查是否是最后一篇文章
你可能会在你的文章列表里面添加些东西(比如广告或推荐),把以下代码添加到循环内,可以让你在最后一篇文章之前显示出添加的东西。


<?php if( ($wp_query->current_post + 1) < ($wp_query->post_count) ): ?>
<div class=”separator”></div>
<?php endif; ?>

判断当前的用户可以做什么…


<?php
if( current_user_can(‘editor’) ):
// true if user is an editor
endif;
if( !current_user_can(‘administrator’) ):
// true if user is not admin
endif;
if( current_user_can(‘edit_posts’) ):
// true if user can edit posts
endif;
?>

除了admin,使别人禁用Tinymce HTML编辑器
把下面的代码添加到functions.php文件里限制只有admin可以使用编辑器


<?php
add_filter( ‘wp_default_editor’, create_function(”, ‘return “tinymce”;’) );
add_action( ‘admin_head’, ‘disable_html_editor_wps’ );
function disable_html_editor_wps() {
global $current_user;
get_currentuserinfo();
if ($current_user->user_level != 10) {
echo ‘<style type=”text/css”>#editor-toolbar #edButtonHTML, #quicktags {display: none;}</style>’;
}
}
?>

你可以把所遇到过的条件标签都整合起来,这些条件标签当你制件主题的时候会很方便,你是否有不同的条件标签,可以拿出来与大家一起分享.