Skip to content

Commit

Permalink
添加公告和友情链接模块
Browse files Browse the repository at this point in the history
  • Loading branch information
owen0o0 committed Feb 22, 2020
1 parent 677ff52 commit d6c1611
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 42 deletions.
8 changes: 8 additions & 0 deletions css/nav.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 32 additions & 5 deletions inc/frame/config/framework.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'menu_icon' => CS_URI.'/assets/images/setting.png',
'ajax_save' => true,
'show_reset_all' => true,
'framework_title' => 'WebStack '.__('主题设置','io_setting').'<style>.cs-framework .cs-body {min-height: 700px;}</style><span style="font-size: 14px;"> - V '.wp_get_theme()->get('Version').'</span> <a href="https://www.iowen.cn/webstack-pro-navigation-theme-advanced/">升级pro</a>',
'framework_title' => 'WebStack '.__('主题设置','io_setting').'<style>.cs-framework .cs-body {min-height: 700px;}</style><span style="font-size: 14px;"> - V '.wp_get_theme()->get('Version').'</span> <a href="https://www.iowen.cn/webstack-pro-navigation-theme-advanced/" target="_blank">升级pro</a>',
//'framework_title' => '主题设置',
);

Expand All @@ -34,7 +34,7 @@
'fields' => array(
array(
'type' => 'notice',
'content' => '网站LOGO和Favicon设置',
'content' => '---》<a href="https://www.iowen.cn/wordpress-version-webstack/" target="_blank">查看教程</a>《---',
'class' => 'info',
),
array(
Expand Down Expand Up @@ -116,6 +116,33 @@
'col-sm-4 col-md-3 col-lg-2' => '6'
),
),



array(
'id' => 'bulletin',
'type' => 'switcher',
'title' => '显示公告',
'desc' => '在首页顶部显示公告',
'default' => true,
),
array(
'id' => 'bulletin_n',
'type' => 'text',
'title' => '公告数量',
'after' => '需要显示的公告篇数',
'default' => 2,
'dependency' => array( 'bulletin', '==', 'true' )
),
array(
'id' => 'links',
'type' => 'switcher',
'title' => '友情链接',
'label' => '在首页底部添加友情链接',
'default' => true,
),


array(
'type' => 'notice',
'content' => '其他设置',
Expand Down Expand Up @@ -172,21 +199,21 @@
'id' => 'ico_url',
'type' => 'text',
'title' => '图标源',
'default' => 'https://api.iowen.cn/favicon/',
'default' => 'https://api.ooopn.com/ico/api.php?url=',
'desc' => 'api 地址',
'after' => '如果获取图标失效,请百度搜索‘获取网站图标api’替换能用的就可以了<br>或者自建api服务,源码地址:<a href="https://www.iowen.cn/favicon-api/" target="_blank">https://www.iowen.cn/favicon-api/</a>',
),
array(
'id' => 'url_format',
'type' => 'switcher',
'title' => '不包含 http(s)://',
'default' => true,
'default' => false,
'desc' => '根据图标源 api 要求设置,如果api要求不能包含协议名称,请开启此选项',
),
array(
'id' => 'ico_png',
'type' => 'text',
'title' => '图标源api后缀',
'default' => '.png',
'desc' => '如:.png ,请根据api格式要求设置,如不需要请留空',
),
),
Expand Down
49 changes: 14 additions & 35 deletions inc/inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
));


//激活友情链接模块
add_filter( 'pre_option_link_manager_enabled', '__return_true' );

require_once get_theme_file_path() .'/inc/frame/cs-framework.php';
require_once get_theme_file_path() .'/inc/register.php';
require_once get_theme_file_path() .'/inc/post-type.php';
Expand Down Expand Up @@ -464,42 +467,8 @@ function walker_nav_menu_start_el( $item_output, $item, $depth, $args ){
}
}
new iconfont();

/**
* 让搜索支持自定义文章
*/
function include_post_types_in_search($query) {
if(is_search()) {
$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
$searchable_types = array();
if($post_types) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set('post_type', $searchable_types);
}
return $query;
}
//add_action('pre_get_posts', 'include_post_types_in_search');


/**
* 让搜索支持自定义字段
*/
//add_action('posts_search', 'include_custom_fields_in_search',2,2);
function include_custom_fields_in_search ($search, $query){
global $wpdb;

if ($query->is_main_query() && !empty($query->query['s'])) {

$sql = " OR EXISTS (SELECT * FROM {$wpdb->postmeta} WHERE post_id={$wpdb->posts}.ID and meta_key = '_sites_sescribe' and meta_value like %s)";
$like = '%' . $wpdb->esc_like($query->query['s']) . '%';

$search .= $wpdb->prepare($sql, $like);
}
return $search;
};


function format_url($url){
if($url == '')
Expand All @@ -514,6 +483,16 @@ function format_url($url){
}
}

# 搜索只查询文章和网址。
# --------------------------------------------------------------------
add_filter('pre_get_posts','searchfilter');
function searchfilter($query) {
//限定对搜索查询和非后台查询设置
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('sites','post'));
}
return $query;
}

/**
* 修改搜索查询的sql代码,将postmeta表左链接进去。
Expand Down
42 changes: 42 additions & 0 deletions inc/post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ function create_sites_taxonomies() {
register_taxonomy( 'favorites', array( 'sites' ), $args );
}


// 公告
add_action( 'init', 'post_type_bulletin' );
function post_type_bulletin() {
$labels = array(
'name' => '公告', 'post type general name', 'your-plugin-textdomain',
'singular_name' => '公告', 'post type singular name', 'your-plugin-textdomain',
'menu_name' => '公告', 'admin menu', 'your-plugin-textdomain',
'name_admin_bar' => '公告', 'add new on admin bar', 'your-plugin-textdomain',
'add_new' => '发布公告', 'bulletin', 'your-plugin-textdomain',
'add_new_item' => '发布新公告', 'your-plugin-textdomain',
'new_item' => '新公告', 'your-plugin-textdomain',
'edit_item' => '编辑公告', 'your-plugin-textdomain',
'view_item' => '查看公告', 'your-plugin-textdomain',
'all_items' => '所有公告', 'your-plugin-textdomain',
'search_items' => '搜索公告', 'your-plugin-textdomain',
'parent_item_colon' => 'Parent 公告:', 'your-plugin-textdomain',
'not_found' => '你还没有发布公告。', 'your-plugin-textdomain',
'not_found_in_trash' => '回收站中没有公告。', 'your-plugin-textdomain'
);

$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'bulletin' ),
'capability_type' => 'post',
'menu_icon' => 'dashicons-controls-volumeon',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 10,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'author', 'comments', 'custom-fields' )
);

register_post_type( 'bulletin', $args );
}


/**
* 分类项目排序字段
*
Expand Down
8 changes: 6 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<div class="main-content">

<?php include( 'templates/header-banner.php' ); ?>

<?php get_template_part( 'templates/bulletin' ); ?>

<?php
if(io_get_option('is_search')){include('search-tool.php'); }
Expand Down Expand Up @@ -48,7 +50,9 @@
}
}
}
} ?>
}
get_template_part( 'templates/friendlink' );
?>
</div>
<?php
get_footer();
get_footer();
38 changes: 38 additions & 0 deletions templates/bulletin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?>
<?php if( io_get_option('bulletin')) : ?>
<div id="bulletin_box" class="panel">
<div class="d-flex text-muted">
<div><i class="fa fa-volume-up" style="line-height:25px"></i></div>
<div class="bulletin mx-1 mx-md-2">
<ul class="bulletin-ul">
<?php
$args = array(
'post_type' => 'bulletin',
'posts_per_page' => io_get_option('bulletin_n')
);
query_posts($args); while ( have_posts() ) : the_post();
?>
<?php the_title( sprintf( '<li class="scrolltext-title overflowClip_1"><a href="%s" rel="bulletin">', esc_url( get_permalink() ) ), '</a> ('. get_the_time('m/d').')</li>' ); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
<a title="关闭" href="javascript:;" rel="external nofollow" onClick="$('#bulletin_box').slideUp('slow');" style="margin-left:auto"><i class="fa fa-remove" style="line-height:25px"></i></a>
</div>
</div>
<script>
$(document).ready(function(){
var ul = $(".bulletin-ul");
var li = ul.children();
if(li.length > 1){
var liHight = $(li[0]).height();
setInterval('AutoScroll(".bulletin",'+liHight+')',4000);
}
});
function AutoScroll(obj,hight){
$(obj).find("ul:first").animate({marginTop:"-"+hight+"px"},500,function(){
$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
});
}
</script>
<?php endif; ?>
12 changes: 12 additions & 0 deletions templates/friendlink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?>

<?php if( io_get_option('links') ) : ?>
<h4 class="text-gray mb-4">
<i class="fa fa-bookmark" id="friendlink" style="margin-right:10px"></i>友情链接
</h4>
<div class="friendlink" style="margin-bottom:-40px">
<div class="panel">
<?php wp_list_bookmarks('title_li=&before=&after=&categorize=0&show_images=0&orderby=rating&order=DESC&category='.get_option('link_f_cat')); ?>
</div>
</div>
<?php endif; ?>

0 comments on commit d6c1611

Please sign in to comment.