Skip to content

Commit

Permalink
档案页增加翻页按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
owen0o0 committed Dec 6, 2019
1 parent 4941d74 commit f8a8c36
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 238 deletions.
30 changes: 11 additions & 19 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,9 @@
include( 'templates/header-nav.php' );
?>
<div class="main-content">
<nav class="navbar user-info-navbar" role="navigation">
<div class="navbar-content">
<ul class="user-info-menu left-links list-inline list-unstyled">
<li class="hidden-xs">
<a href="#" data-toggle="sidebar">
<i class="fa fa-bars"></i>
</a>
</li>
<li>
<div id="he-plugin-simple"></div>
<script>WIDGET = {CONFIG: {"modules": "12034","background": 5,"tmpColor": "aaa","tmpSize": 16,"cityColor": "aaa","citySize": 16,"aqiSize": 16,"weatherIconSize": 24,"alertIconSize": 18,"padding": "30px 10px 30px 10px","shadow": "1","language": "auto","borderRadius": 5,"fixed": "false","vertical": "middle","horizontal": "left","key": "a922adf8928b4ac1ae7a31ae7375e191"}}</script>
<script src="https://widget.heweather.net/simple/static/js/he-simple-common.js?v=1.1"></script>
</li>
</ul>
</div>
<a href="https://github.com/owen0o0/WebStack" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
</nav>

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

<?php
if(io_get_option('is_search')){include('search-tool.php'); }
else{?>
Expand All @@ -51,7 +37,13 @@
<?php endif; endwhile; endif;?>
</div>
<br />

分页功能

<div class="posts-nav">
<?php echo paginate_links(array(
'prev_next' => 0,
'before_page_number' => '',
'mid_size' => 2,
));?>
</div>

<?php get_footer(); ?>
65 changes: 36 additions & 29 deletions css/nav.css

Large diffs are not rendered by default.

52 changes: 51 additions & 1 deletion inc/inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ 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');
Expand All @@ -479,6 +482,22 @@ function include_post_types_in_search($query) {
}
add_action('pre_get_posts', 'include_post_types_in_search');

/**
* 让搜索支持自定义字段
*/
add_action('posts_search', function($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;
},2,2);

function format_url($url){
if($url == '')
return;
Expand All @@ -490,4 +509,35 @@ function format_url($url){
else{
return $url;
}
}
}

// 分页代码
function pagination($query_string){
global $posts_per_page, $paged;
$my_query = new WP_Query($query_string ."&posts_per_page=-1");
$total_posts = $my_query->post_count;
if(empty($paged))$paged = 1;
$prev = $paged - 1;
$next = $paged + 1;
$range = 2; // only edit this if you want to show more page-links
$showitems = ($range * 2)+1;

$pages = ceil($total_posts/$posts_per_page);
if(1 != $pages){
echo "<div class='pagination'>";
echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? "<a href='".get_pagenum_link(1)."'>最前</a>":"";
echo ($paged > 1 && $showitems < $pages)? "<a href='".get_pagenum_link($prev)."'>上一页</a>":"";

for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}

echo ($paged < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($next)."'>下一页</a>" :"";
echo ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($pages)."'>最后</a>":"";
echo "</div>\n";
}
}


16 changes: 8 additions & 8 deletions inc/post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function post_type_sites() {
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'sites' ),
'rewrite' => array( 'slug' => 'site' ),
'capability_type' => 'post',
'menu_icon' => 'dashicons-admin-site',
'has_archive' => false,
Expand Down Expand Up @@ -65,7 +65,7 @@ function create_sites_taxonomies() {
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'sites' ),
'rewrite' => array( 'slug' => 'favorites' ),
);

register_taxonomy( 'favorites', array( 'sites' ), $args );
Expand Down Expand Up @@ -134,21 +134,21 @@ function save_term_order( $term_id ) {
*/
add_filter('post_type_link', 'custom_sites_link', 1, 3);
function custom_sites_link( $link, $post = 0 ){
if ( $post->post_type == 'sites' ){
return home_url( 'sites/' . $post->ID .'.html' );
if ( $post->post_type == 'site' ){
return home_url( 'site/' . $post->ID .'.html' );
} else {
return $link;
}
}
add_action( 'init', 'custom_sites_rewrites_init' );
function custom_sites_rewrites_init(){
add_rewrite_rule(
'sites/([0-9]+)?.html$',
'index.php?post_type=sites&p=$matches[1]',
'site/([0-9]+)?.html$',
'index.php?post_type=site&p=$matches[1]',
'top' );
add_rewrite_rule(
'sites/([0-9]+)?.html/comment-page-([0-9]{1,})$',
'index.php?post_type=sites&p=$matches[1]&cpage=$matches[2]',
'site/([0-9]+)?.html/comment-page-([0-9]{1,})$',
'index.php?post_type=site&p=$matches[1]&cpage=$matches[2]',
'top'
);
}
20 changes: 3 additions & 17 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,9 @@
include( 'templates/header-nav.php' );
?>
<div class="main-content">
<nav class="navbar user-info-navbar" role="navigation">
<div class="navbar-content">
<ul class="user-info-menu left-links list-inline list-unstyled">
<li class="hidden-xs">
<a href="#" data-toggle="sidebar">
<i class="fa fa-bars"></i>
</a>
</li>
<li>
<div id="he-plugin-simple"></div>
<script>WIDGET = {CONFIG: {"modules": "12034","background": 5,"tmpColor": "aaa","tmpSize": 16,"cityColor": "aaa","citySize": 16,"aqiSize": 16,"weatherIconSize": 24,"alertIconSize": 18,"padding": "30px 10px 30px 10px","shadow": "1","language": "auto","borderRadius": 5,"fixed": "false","vertical": "middle","horizontal": "left","key": "a922adf8928b4ac1ae7a31ae7375e191"}}</script>
<script src="https://widget.heweather.net/simple/static/js/he-simple-common.js?v=1.1"></script>
</li>
</ul>
</div>
<a href="https://github.com/owen0o0/WebStack" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
</nav>

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

<?php
if(io_get_option('is_search')){include('search-tool.php'); }
else{?>
Expand Down
40 changes: 21 additions & 19 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@
include( 'templates/header-nav.php' );
?>
<div class="main-content page">
<div class="row">
<div class="col-12 col-lg-10 mx-auto">
<div class="panel panel-default">
<h1><?php echo get_the_title() ?></h1>
<div class="panel-body mt-2">
<div class="row">
<div class="col-sm-12">
<?php while( have_posts() ): the_post(); ?>
<?php the_content();?>
<?php edit_post_link(__('编辑','i_owen'), '<span class="edit-link">', '</span>' ); ?>
<?php endwhile; ?>
</div>
<div class="container">
<div class="row">
<div class="col-12 mx-auto">
<div class="panel panel-default">
<h1 class="h2"><?php echo get_the_title() ?></h1>
<div class="panel-body mt-2">
<div class="row">
<div class="col-sm-12">
<?php while( have_posts() ): the_post(); ?>
<?php the_content();?>
<?php edit_post_link(__('编辑','i_owen'), '<span class="edit-link">', '</span>' ); ?>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
<?php
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
</div>
<?php
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
</div>
</div>
</div>
<?php get_footer(); ?>
5 changes: 3 additions & 2 deletions search-tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ul class="search-type">
<li><input checked hidden type="radio" name="type" id="type-baidu" value="https://www.baidu.com/s?wd=" data-placeholder="百度一下"><label for="type-baidu"><span style="color:#2100E0">百度</span></label></li>
<li><input hidden type="radio" name="type" id="type-google" value="https://www.google.com/search?q=" data-placeholder="谷歌两下"><label for="type-google"><span style="color:#3B83FA">G</span><span style="color:#F3442C">o</span><span style="color:#FFC300">o</span><span style="color:#4696F8">g</span><span style="color:#2CAB4E">l</span><span style="color:#F54231">e</span></label></li>
<li><input hidden type="radio" name="type" id="type-zhannei" value="?s=" data-placeholder="站内搜索"><label for="type-zhannei"><span style="color:#888888">站内</span></label></li>
<li><input hidden type="radio" name="type" id="type-zhannei" value="<?php bloginfo('url') ?>?s=" data-placeholder="站内搜索"><label for="type-zhannei"><span style="color:#888888">站内</span></label></li>
<li><input hidden type="radio" name="type" id="type-taobao" value="https://s.taobao.com/search?q=" data-placeholder="淘宝"><label for="type-taobao"><span style="color:#f40">淘宝</span></label></li>
<li><input hidden type="radio" name="type" id="type-bing1" value="https://cn.bing.com/search?q=" data-placeholder="微软Bing搜索"><label for="type-bing1"><span style="color:#007daa">Bing</span></label></li>
</ul>
Expand Down Expand Up @@ -79,8 +79,9 @@
</div>
<form action="?s=" method="get" target="_blank" id="super-search-fm"><input type="text" id="search-text" placeholder="输入关键字搜索" style="outline:0"><button type="submit"><i class="fa fa-search "></i></button></form>
<div class="set-check hidden-xs">
<input type="checkbox" id="set-search-blank" class="bubble-3" autocomplete="off"></div>
<input type="checkbox" id="set-search-blank" class="bubble-3" autocomplete="off">
</div>
</div>
<script type="text/javascript">
eval(function(e,t,a,c,i,n){if(i=function(e){return(e<t?"":i(parseInt(e/t)))+(35<(e%=t)?String.fromCharCode(e+29):e.toString(36))},!"".replace(/^/,String)){for(;a--;)n[i(a)]=c[a]||i(a);c=[function(e){return n[e]}],i=function(){return"\\w+"},a=1}for(;a--;)c[a]&&(e=e.replace(new RegExp("\\b"+i(a)+"\\b","g"),c[a]));return e}('!2(){2 g(){h(),i(),j(),k()}2 h(){d.9=s()}2 i(){z a=4.8(\'A[B="7"][5="\'+p()+\'"]\');a&&(a.9=!0,l(a))}2 j(){v(u())}2 k(){w(t())}2 l(a){P(z b=0;b<e.O;b++)e[b].I.1c("s-M");a.F.F.F.I.V("s-M")}2 m(a,b){E.H.S("L"+a,b)}2 n(a){6 E.H.Y("L"+a)}2 o(a){f=a.3,v(u()),w(a.3.5),m("7",a.3.5),c.K(),l(a.3)}2 p(){z b=n("7");6 b||a[0].5}2 q(a){m("J",a.3.9?1:-1),x(a.3.9)}2 r(a){6 a.11(),""==c.5?(c.K(),!1):(w(t()+c.5),x(s()),s()?E.U(b.G,+T X):13.Z=b.G,10 0)}2 s(){z a=n("J");6 a?1==a:!0}2 t(){6 4.8(\'A[B="7"]:9\').5}2 u(){6 4.8(\'A[B="7"]:9\').W("14-N")}2 v(a){c.1e("N",a)}2 w(a){b.G=a}2 x(a){a?b.3="1a":b.16("3")}z y,a=4.R(\'A[B="7"]\'),b=4.8("#18-C-19"),c=4.8("#C-12"),d=4.8("#17-C-15"),e=4.R(".C-1b"),f=a[0];P(g(),y=0;y<a.O;y++)a[y].D("Q",o);d.D("Q",q),b.D("1d",r)}();',62,77,"||function|target|document|value|return|type|querySelector|checked||||||||||||||||||||||||||var|input|name|search|addEventListener|window|parentNode|action|localStorage|classList|newWindow|focus|superSearch|current|placeholder|length|for|change|querySelectorAll|setItem|new|open|add|getAttribute|Date|getItem|href|void|preventDefault|text|location|data|blank|removeAttribute|set|super|fm|_blank|group|remove|submit|setAttribute".split("|"),0,{}));
</script>
17 changes: 15 additions & 2 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

<a href="<?php bloginfo('url') ?>" style="position:absolute;margin:30px 0 0 30px;z-index:1000;"><img src="<?php echo io_get_option('logo_normal') ?>" height="40" alt="<?php bloginfo('name') ?>"></a>
<div class="main-content">
<?php include('search-tool.php'); ?>
<div id="search" class="s-search">
<form name="formsearch" method="get" action="<?php bloginfo('url'); ?>?s=" id="super-search-fm">
<input type="text" id="search-text" name="s" class="search-keyword" placeholder="输入关键字搜索" style="outline:0"/>
<button type="submit" οnmοuseοut="this.className='select_class'" οnmοuseοver="this.className='select_over'" ><i class="fa fa-search "></i></button>
</form>
</div>

<div class="row">
<div class="col-12 col-lg-8 mx-auto">
<h4 class="text-gray"><i class="fa fa-search" style="margin-right: 27px;"></i>“<?php echo $s; ?><?php _e('的搜索结果','i_swallow'); ?></h4>
Expand All @@ -29,8 +35,15 @@
<?php include( 'templates/site-card.php' ); ?>
</div>
<?php endif; endwhile; endif;?>
</div>
</div>
<br />
<div class="posts-nav">
<?php echo paginate_links(array(
'prev_next' => 0,
'before_page_number' => '',
'mid_size' => 2,
));?>
</div>
<div style="text-align:center;margin-top:50px;margin-bottom:30px;">
<a href="<?php bloginfo('url') ?>" class="but-home ">返回主页</a>
</div>
Expand Down
Loading

0 comments on commit f8a8c36

Please sign in to comment.