function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-20,-21,-22,-23,-32' );
}
return $query;
}
add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-20,-21,-22,-23,-32' );
}
return $query;
}
add_filter('pre_get_posts', 'excludeCat');
WordPress 自带的标签云是一个很实用的小工具。站长可以通过标签对具有相同关健词的文章进行检索分类,利于访客查找相关文章。WordPress 默认标签云的字体最小为8pt,最大为22pt,标签显示数量为45个,按标签名称升序排列。但是这个默认的标签云有时在与选定的模板相结合时显得不那么美观,这就需要我们对标签云的默认参数进行修改。方法很简单,就是修改 WordPress 代码中标签云调用函数 wp_tag_cloud 的各项参数。
打开 wp-includes/category-template.php 搜索 wp_tag_cloud 找到
‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,’format’ => ‘flat’, ‘separator’ => “\n”, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,
具体的参数说明:
1. smallest – 定义标签的最小字号,默认为 8;
2. largest – 定义标签的最大字号,默认为 22;
3. unit – 设置字号类型,如 “pt” 或 “px” 等,默认为 “pt” 类型;
4. number – 设置标签云数量,默认显示 45 个标签;
5. orderby – 设置按 “name” 或 “count” 排序,默认为 “name” 方式;(注:orderby=count 表示按照标签使用次数排列)
6. order – 设置按 “DESC” 或 “ASC” 升降序排列,默认为 “ASC” 升序。
wordpress的标签云变成彩色方法:
打开wp-content/themes/你模板/下面的:functions.php 文件 只需要把以下代码加入里面:(加入的位置可以在多个地方,大家都推荐在:Custom Comment前面)
//Color Tag Cloud
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text);
return $text;
}
function colorCloudCallback($matches) {
$text = $matches[1];
$color = dechex(rand(0,16777215));
$pattern = '/style=(\'|\")(.*)(\'|\")/i';
$text = preg_replace($pattern, "style=\"color:#{$color};$2;\"", $text);
return "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
1,去等登陆页的-wordpress
打开网站目录wp-login.php找到下列代码并进修改
$login_title = sprintf( __( '%1$s ‹ %2$s — 张先生' ), $title, $login_title );
2,去除后台的-wordpress
打开网站目录找到wp-admin/admin-header.php找到下列代码并进修改【共2处需要修改】
if ( $admin_title === $title ) {
/* translators: Admin screen title. %s: Admin screen name. */
$admin_title = sprintf( __( '%s — 张正小师傅' ), $title );
} else {
$screen_title = $title;
if ( 'post' === $current_screen->base && 'add' !== $current_screen->action ) {
$post_title = get_the_title();
if ( ! empty( $post_title ) ) {
$post_type_obj = get_post_type_object( $typenow );
$screen_title = sprintf(
/* translators: Editor admin screen title. 1: "Edit item" text for the post type, 2: Post title. */
__( '%1$s “%2$s”' ),
$post_type_obj->labels->edit_item,
$post_title
);
}
}
/* translators: Admin screen title. 1: Admin screen name, 2: Network or site name. */
$admin_title = sprintf( __( '%1$s ‹ %2$s — 张正小师傅' ), $screen_title, $admin_title );
}
linux解压.tar.gz文件命令
tar -zxvf web_ziyou.zhang136.fun_20221104_013001.tar.gz
.page-header {display: none;}
我们可以在当前wordpress建站主题的functions.php文件中添加下面的代码:
function custom_loginlogo() {
echo '<style type="text/css">
h1 a {background-image: url('.get_bloginfo('template_directory').'/images/login_logo.png) !important; }
</style>';
}
add_action('login_head', 'custom_loginlogo');
接下来把你自己的LOGO文件名修改为【login_logo.png】,然后上传到当前wordpress建站主题目录下的【images】文件夹中,如果没有这个文件夹,可以自己新建一个。
接下来我们还城朵打开wp-login.php文件,找到【$login_header_url= __( ‘http://wordpress.org/’)】,把里面的链接修改为你自己的,比如改为首页的。
//移除左上角Wlog
function annointed_admin_bar_remove() {
global $wp_admin_bar;
/* Remove their stuff */
$wp_admin_bar->remove_menu(‘wp-logo’);
}
add_action(‘wp_before_admin_bar_render’, ‘annointed_admin_bar_remove’, 0);
//移除Wordpress后台“感谢使用wordpress创作”
function my_admin_footer_text(){
return “”;
}
function my_update_footer()
{
return “”;
}
add_filter( ‘admin_footer_text’, ‘my_admin_footer_text’, 10 );
add_filter( ‘update_footer’, ‘my_update_footer’, 50 );
//修改登录页面logo
function custom_loginlogo() {
echo ”;
}
add_action(‘login_head’, ‘custom_loginlogo’);
//禁用后台登录页语言切换
add_filter( ‘login_display_language_dropdown’, ‘__return_false’ );
//让wordpress首页隐藏某一分类的文章
function excludeCat($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-20,-21,-22,-23,-32’ );
}
return $query;
}
add_filter(‘pre_get_posts’, ‘excludeCat’);
//设置登录查看网站内容
add_action( ‘template_redirect’, ‘ashuwp_show_only_login’, 0 );
function ashuwp_show_only_login(){
//判断登录
if( !is_user_logged_in() ){
auth_redirect(); //跳转到登录页面
exit();
}
}