Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
新增后台功能
  • Loading branch information
ghboke committed Aug 2, 2019
1 parent 58ab4c7 commit 686292a
Show file tree
Hide file tree
Showing 21 changed files with 523 additions and 49 deletions.
4 changes: 2 additions & 2 deletions 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
?>

<div class="layui-container" id="main">
<div class="blog-title"><img class="toobar-icon" src="<?php echo getImgDir('folder.png') ?>"
<div class="blog-title"><img class="toobar-icon" src="<?php echo getImgDir('folder.ico') ?>"
alt=""><?php /*bloginfo('name');*/
echo "网站管理器" ?>
<div class="post-title"> - <?php the_title(); ?></div>
Expand All @@ -26,7 +26,7 @@
<i class="fa fa-arrow-up" aria-hidden="true"></i></div>
</div>
<div class="layui-col-md9 layui-col-xs-12 layui-col-sm-12">
<div class="toolbar-url"><img class="toobar-icon" src="<?php echo getImgDir('folder.png') ?>"
<div class="toolbar-url"><img class="toobar-icon" src="<?php echo getImgDir('folder.ico') ?>"
alt=""><span><a href="//<?php echo $_SERVER['SERVER_NAME']; ?>">本网站</span></a>><span>404页面</span>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
顶部菜单为导航菜单,暂时只支持最高二级菜单,可以自己设置,侧边栏支持列表美化,其他的美化没做,第一个版本,会慢慢完善和更新的。

其他美化:H2标签,表格等
支持自定义设置,后台带设置面板,支持SEO设置。
![win10explore](/img/win10exp01.png)
![win10explore](/img/win10exp02.png)
![win10explore](/img/win10exp03.png)
## 更新日志
2019-8-2
新增后台设置面板,允许配置SEO
新增自动SEO功能,能自动截取文章内容作为摘要,和设置关键词,关键词来源于标签。
可以自己后台配置网站标题图标,文章列表前面的小图标
主题支持检查更新
优化默认的小图标为txt图标,文件夹图标优化和win10一致
2019-7-25
简单优化了一下搜索侧边栏
添加引用块样式
Expand Down
7 changes: 3 additions & 4 deletions category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
?>

<div class="layui-container" id="main">
<div class="blog-title"><img class="toobar-icon" src="<?php echo getImgDir('folder.png') ?>"
alt=""><?php /*bloginfo('name');*/
echo bloginfo('name') ?>
<div class="blog-title"><?php obj_title_icon();
bloginfo('name'); ?>
<div class="close"><i class="layui-icon layui-icon-close"></i>
</div>
</div>
Expand All @@ -26,7 +25,7 @@
class="fa fa-arrow-up" aria-hidden="true"></i></div>
</div>
<div class="layui-col-md9 layui-col-xs-12 layui-col-sm-12">
<div class="toolbar-url"><img class="toobar-icon" src="<?php echo getImgDir('folder.png') ?>"
<div class="toolbar-url"><img class="toobar-icon" src="<?php echo getImgDir('folder.ico') ?>"
alt=""><span><a href="//<?php echo $_SERVER['SERVER_NAME']; ?>">本网站</a></span>><span><a href="<?php echo get_category_link($catid)?>"><?php echo get_cat_name($catid)?></a></span></div>
</div>
<div class="layui-col-md2 <?php get_self_adaption_css()?>">
Expand Down
38 changes: 37 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php
//获取设置
define('THEME_ID', 'lovestutheme01'); // 主题ID,请勿修改,否则可能导致配置错误
define('THEME_VERSION', '1.3.0'); // 主题内部版本号,请勿修改,否则可能导致配置错误
define('THEME_ID_SET', 'lovestutheme01_set');

global $theme_option;

theme_int_set();
include_once 'inc/obj.php';
include_once 'inc/ajax.php';
//add_filter('get_avatar', 'my_custom_avatar', 1, 5);
function my_custom_avatar($avatar, $id_or_email, $size, $default, $alt)
{
Expand Down Expand Up @@ -63,7 +72,7 @@ function my_comment($comment, $args, $depth)
} ?>
</div>
<div class="media-body">
<?php echo __('<p class="author_name">'). get_comment_author_link().$reply.'</p>'; ?>
<?php echo __('<p class="author_name">') . get_comment_author_link() . $reply . '</p>'; ?>
<?php if ($comment->comment_approved == '0') : ?>
<em>评论等待审核...</em><br/>
<?php endif; ?>
Expand All @@ -82,4 +91,31 @@ function my_comment($comment, $args, $depth)
<?php
}

add_action('admin_menu', 'theme_options_menu');
function theme_options_menu()
{
add_menu_page('主题设置', '主题设置', 'administrator', 'theme_options_menu', 'theme_settings_admin', 'dashicons-admin-appearance');
}

function theme_settings_admin()
{
include_once get_template_directory() . "/inc/page-options.php";
}


function theme_int_set()
{
global $theme_option;
$theme_option = get_option(THEME_ID_SET);
if ($theme_option == false || $theme_option == '{}') {
$theme_option = array('seo' => 0, 'single_icon' => '', 'index_title' => '', 'site_description' => '', 'site_key' => '', 'autoseo' => 0,'version'=>THEME_VERSION);

update_option(THEME_ID_SET, json_encode($theme_option));
$theme_option = json_decode(json_encode($theme_option), true);
} else {
$theme_option = json_decode($theme_option, true);
}

}

?>
11 changes: 7 additions & 4 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?php get_blog_title_obj()?></title>
<meta name="description" content="<?php bloginfo('description'); ?>"/>
<title><?php get_blog_title_obj() ?></title>
<?php obj_seo_set(); ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css"/>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri().'/static/layui/css/layui.css'?>" type="text/css"/>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri().'/static/font-awesome/css/font-awesome.css'?>"type="text/css"/>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri() . '/static/layui/css/layui.css' ?>"
type="text/css"/>
<link rel="stylesheet"
href="<?php echo get_stylesheet_directory_uri() . '/static/font-awesome/css/font-awesome.css' ?>"
type="text/css"/>
<?php wp_head(); ?>
</head>
<body>
Expand Down
Binary file added img/win10exp03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions inc/ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
function fun_save_set()
{
global $theme_option;
$theme_option['seo'] = $_POST['seo'];
$theme_option['autoseo'] = $_POST['autoseo'];
$theme_option['site_description'] = $_POST['site_description'];
$theme_option['site_key'] = $_POST['site_key'];
$theme_option['index_title'] = $_POST['index_title'];
$theme_option['site_name'] = $_POST['site_name'];
$theme_option['single_icon'] = $_POST['single_icon'];
$theme_option['title_icon'] = $_POST['title_icon'];
update_option(THEME_ID_SET, json_encode($theme_option));
echo 1;
wp_die();
}
function fun_check_version(){
$http = new WP_Http;
$result = $http->request( 'https://www.lovestu.com/api/theme.php?a=checkversion&theme=win10exp' );

$result= json_decode($result['body'], true);
if (is_array($result)){
echo $result['version'];
}else{
echo '0';
}
wp_die();
}
add_action('wp_ajax_save_set', 'fun_save_set');
add_action('wp_ajax_check_version', 'fun_check_version');
131 changes: 111 additions & 20 deletions inc/obj.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function postlist($cateid)
<div class="view"><?php the_views(true); ?></div>
</td>
</tr>

<?php
}

Expand All @@ -61,22 +60,29 @@ function default_post()
return;
}
global $post;
global $theme_option;
if ($theme_option['single_icon'] == '') {
$single_icon_src = getImgDir('txt.png');

} else {
$single_icon_src = $theme_option['single_icon'];
}
?>
<div class="layui-row">
<div class="layui-col-md8 post-namelist-title">名称</div>
<div class="layui-col-md2 post-namelist-title <?php get_self_adaption_css()?>">修改日期</div>
<div class="layui-col-md2 post-namelist-title <?php get_self_adaption_css()?>">阅读</div>
<div class="layui-col-md2 post-namelist-title <?php get_self_adaption_css() ?>">修改日期</div>
<div class="layui-col-md2 post-namelist-title <?php get_self_adaption_css() ?>">阅读</div>
</div>
<?php
while (have_posts()) {
the_post();
?>
<div class="layui-row post-list-post">
<div class="layui-col-md7 layui-col-sm12 layui-col-xs12"><img class="postlist-table-icon"
src="<?php echo get_stylesheet_directory_uri() . '/static/img/txt.png' ?>"><a
href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="layui-col-md3 <?php get_self_adaption_css()?>"><?php the_time('Y-m-d/D G:i') ?></div>
<div class="layui-col-md2 <?php get_self_adaption_css()?>"><?php the_views(true); ?></div>
src="<?php echo $single_icon_src; ?>"><a
href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="layui-col-md3 <?php get_self_adaption_css() ?>"><?php the_time('Y-m-d/D G:i') ?></div>
<div class="layui-col-md2 <?php get_self_adaption_css() ?>"><?php the_views(true); ?></div>
</div>
<?php
}
Expand All @@ -93,19 +99,34 @@ function get_search_obj()

function get_blog_title_obj()
{
global $theme_option;
$blogname = get_bloginfo('name');
if (is_home()) {
echo $blogname;
if ($theme_option['seo'] != 1) {
echo $blogname;
} else {
if ($theme_option['index_title'] == '') {
echo $blogname;
} else {
echo $theme_option['index_title'];
}

}
} elseif (is_category()) {
single_cat_title();
if ($theme_option['seo'] != 1) {
echo ' - ' . $blogname;
} else {
echo ' - ' . $theme_option['site_name'];
}

} elseif (is_single() || is_page()) {
single_post_title();
echo ' - '.$blogname;
} elseif (is_single()) {
single_post_title();
echo ' - '.$blogname;
} elseif (is_page()) {
single_post_title();
echo ' - '.$blogname;

if ($theme_option['seo'] != 1) {
echo ' - ' . $blogname;
} else {
echo ' - ' . $theme_option['site_name'];
}
} else {
wp_title('', true);
}
Expand All @@ -123,11 +144,11 @@ function get_nav_menu_obj()
)); //调用第一个菜单
}

function get_self_adaption_css($where='all')
function get_self_adaption_css($where = 'all')
{
if ($where=='all'){
if ($where == 'all') {
echo 'layui-hide-xs layui-hide-sm layui-show-md-block';
}elseif ($where=='toolbar'){
} elseif ($where == 'toolbar') {
echo 'layui-show-md-block';
}

Expand Down Expand Up @@ -155,4 +176,74 @@ function aurelius_comment($comment, $args, $depth)
</div>
</div>
</li>
<?php } ?>
<?php }

function obj_seo_set()
{
global $theme_option;

if ($theme_option['seo'] != 1) {
return;
}
$description = '';
$keywords = '';

if (is_home()) {
$description = $theme_option['site_description'];
if ($theme_option['site_description'] == '') {
$description = bloginfo('description');
}
$keywords = $theme_option['site_key'];
} elseif (is_single() || is_page()) {

if ($theme_option['autoseo'] != 1) {
return;
}
global $post;
$description = str_replace("\n", "", mb_strimwidth(strip_tags($post->post_content), 0, 200, "", 'utf-8'));

// 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述

// 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词

$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag) {
$keywords = $keywords . $tag->name . ", ";
}
$keywords = rtrim($keywords, ', ');

} elseif (is_category()) {
// 分类的description可以到后台 - 文章 -分类目录,修改分类的描述
$description = category_description();
$keywords = single_cat_title('', false);
} elseif (is_tag()) {
// 标签的description可以到后台 - 文章 - 标签,修改标签的描述
$description = tag_description();
$keywords = single_tag_title('', false);
}
$description = trim(strip_tags($description));
$keywords = trim(strip_tags($keywords));
?>
<meta name="keywords" content="<?php echo $keywords; ?>"/>
<meta name="description" content="<?php echo $description; ?>"/>
<?php
}

function obj_title_icon()
{
global $theme_option;
if ($theme_option['title_icon'] == '') {
$src = getImgDir('folder.ico');
} else {
$src = $theme_option['title_icon'];
}
?>
<img class="toobar-icon"
src="<?php echo $src ?>"
alt="">
<?php

}

?>

Loading

0 comments on commit 686292a

Please sign in to comment.