diff --git a/ajax-comment/app.css b/ajax-comment/app.css new file mode 100644 index 0000000..5eab0a2 --- /dev/null +++ b/ajax-comment/app.css @@ -0,0 +1,25 @@ +.butterBar { + margin-left: 36%; + max-width: 640px; + position: fixed; + text-align: center; + top: 0; + width: 58%; + z-index: 800 +} + +.butterBar--center { + left: 50%; + margin-left: -320px +} + +.butterBar-message { + background: rgba(255, 255, 255, 0.97); + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 0 1px rgba(0, 0, 0, 0.35); + display: inline-block; + font-size: 14px; + margin-bottom: 0; + padding: 12px 25px +} diff --git a/ajax-comment/app.js b/ajax-comment/app.js new file mode 100644 index 0000000..605400e --- /dev/null +++ b/ajax-comment/app.js @@ -0,0 +1,69 @@ +$(document).ready(function ($) { + var __cancel = $('#cancel-comment-reply-link'), + __cancel_text = __cancel.text(), + __list = 'commentlist';//your comment wrapprer + $(document).on("submit", "#commentform", function () { + $.ajax({ + url: ajaxcomment.ajax_url, + data: $(this).serialize() + "&action=ajax_comment", + type: $(this).attr('method'), + beforeSend: faAjax.createButterbar("提交中...."), + error: function (request) { + var t = faAjax; + t.createButterbar(request.responseText); + }, + success: function (data) { + $('textarea').each(function () { + this.value = '' + }); + var t = faAjax, + cancel = t.I('cancel-comment-reply-link'), + temp = t.I('wp-temp-form-div'), + respond = t.I(t.respondId), + post = t.I('comment_post_ID').value, + parent = t.I('comment_parent').value; + if (parent != '0') { + $('#comment-nav').before('
    ' + data + '
'); + } else if (!$('.' + __list).length) { + if (ajaxcomment.formpostion == 'bottom') { + $('#respond').before('
    ' + data + '
'); + } else { + $('#respond').after('
    ' + data + '
'); + } + + } else { + if (ajaxcomment.order == 'asc') { + $('.' + __list).append(data); // your comments wrapper + } else { + $('.' + __list).prepend(data); // your comments wrapper + } + } + t.createButterbar("提交成功"); + cancel.style.display = 'none'; + cancel.onclick = null; + t.I('comment_parent').value = '0'; + if (temp && respond) { + temp.parentNode.insertBefore(respond, temp); + temp.parentNode.removeChild(temp) + } + } + }); + return false; + }); + faAjax = { + I: function (e) { + return document.getElementById(e); + }, + clearButterbar: function (e) { + if ($(".butterBar").length > 0) { + $(".butterBar").remove(); + } + }, + createButterbar: function (message) { + var t = this; + t.clearButterbar(); + $("body").append('

' + message + '

'); + setTimeout("$('.butterBar').remove()", 3000); + } + }; +}); \ No newline at end of file diff --git a/ajax-comment/main.php b/ajax-comment/main.php new file mode 100644 index 0000000..153ecbe --- /dev/null +++ b/ajax-comment/main.php @@ -0,0 +1,84 @@ + admin_url('admin-ajax.php'), + 'order' => get_option('comment_order'), + 'formpostion' => 'bottom', //默认为bottom,如果你的表单在顶部则设置为top。 + ) ); + } + +endif; + +if(!function_exists('fa_ajax_comment_err')) : + + function fa_ajax_comment_err($a) { + header('HTTP/1.0 500 Internal Server Error'); + header('Content-Type: text/plain;charset=UTF-8'); + echo $a; + exit; + } + +endif; + +if(!function_exists('fa_ajax_comment_callback')) : + + function fa_ajax_comment_callback(){ + $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); + if ( is_wp_error( $comment ) ) { + $data = $comment->get_error_data(); + if ( ! empty( $data ) ) { + fa_ajax_comment_err($comment->get_error_message()); + } else { + exit; + } + } + $user = wp_get_current_user(); + do_action('set_comment_cookies', $comment, $user); + $GLOBALS['comment'] = $comment; //根据你的评论结构自行修改,如使用默认主题则无需修改 + ?> +
  • +
    +
    + +
    +
    + %s'), get_comment_author_link()); + echo " " . TM_GetUserAgent($comment->comment_agent) . "

    "; ?> + comment_approved == '0') : ?> + 评论等待审核...
    + + +
    +
    +
    + -
    +

    共有 条评论

    +
    Loading...
    -
    diff --git a/functions.php b/functions.php index b700733..9da5072 100644 --- a/functions.php +++ b/functions.php @@ -345,6 +345,42 @@ function TM_GetUserAgent($ua) return $br; } +//Ajax 评论 +require('ajax-comment/main.php'); +/** + * 修改评论回复按钮链接 + */ +global $wp_version; +if (version_compare($wp_version, '5.1.1', '>=')) { + add_filter('comment_reply_link', 'haremu_replace_comment_reply_link', 10, 4); + function haremu_replace_comment_reply_link($link, $args, $comment, $post) + { + if (get_option('comment_registration') && !is_user_logged_in()) { + $link = sprintf( + '', + esc_url(wp_login_url(get_permalink())), + $args['login_text'] + ); + } else { + $onclick = sprintf( + 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', + $args['add_below'], + $comment->comment_ID, + $args['respond_id'], + $post->ID + ); + $link = sprintf( + "%s", + esc_url(add_query_arg('replytocom', $comment->comment_ID, get_permalink($post->ID))) . "#" . $args['respond_id'], + $onclick, + esc_attr(sprintf($args['reply_to_text'], $comment->comment_author)), + $args['reply_text'] + ); + } + return $link; + } +} + //自定义评论列表模板,来自 https://dedewp.com/17366.html function zmblog_comment($comment, $args, $depth) { @@ -357,23 +393,24 @@ function zmblog_comment($comment, $args, $depth) } ?>
    - %s

    '), get_comment_author_link()); ?> - comment_agent); ?> + %s'), get_comment_author_link()); + echo " " . TM_GetUserAgent($comment->comment_agent) . "

    "; ?> comment_approved == '0') : ?> 评论等待审核...
    -
    -
    -
    -
    + +
    +
    + diff --git a/header.php b/header.php index 008038e..734f117 100644 --- a/header.php +++ b/header.php @@ -9,13 +9,13 @@ - - - - "/> - - "/> - + + + + "/> + + "/> + @@ -39,7 +39,7 @@ class="mdui-icon material-icons">menu class="mdui-icon material-icons">search -
    "> + ">
    diff --git a/js/style.js b/js/style.js index 8fe8833..8572b49 100644 --- a/js/style.js +++ b/js/style.js @@ -34,3 +34,38 @@ var toTop = new ScrollToTop("#toTop", { speed: 50, fadeSpeed: 12 }); + +//目录跳转 +$('a').click(function (event) { + // 此处正则用于转换带页面URL的锚点,如 http://abc.html#div,具体正则格式据实际情况而定 + var targetId = $(this).attr('href'); + $("html,body").animate({scrollTop: $(targetId).offset().top}, 500); +}); + +//Ajax 评论翻页,来自 https://www.mzihen.com/wordpress-ajax-comments-pages/ +$(document).ready(function ($) { + $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');//commentnav ajax + $(document).on('click', '.comment-navigation a', function (e) { + e.preventDefault(); + $.ajax({ + type: "GET", + url: $(this).attr('href'), + beforeSend: function () { + $('.comment-navigation').remove(); + $('.commentlist').remove(); + $('.comments-loading').slideDown(); + }, + dataType: "html", + success: function (out) { + result = $(out).find('.commentlist'); + nextlink = $(out).find('.comment-navigation'); + $('.comments-loading').slideUp(550); + $('.comments-loading').after(result.fadeIn(800)); + $('.commentlist').after(nextlink); + + } + }); + }); +}); + + diff --git a/page.php b/page.php index 7b87945..b67a35d 100644 --- a/page.php +++ b/page.php @@ -24,11 +24,44 @@ class="mdui-text-color-white tm-index-single-title">
    -
    -

    +
    + +

    + + + +
    + +
    + + +
    +

    目录

    + +
    +
    +
    +
    -

    本文采用 CC BY-NC-SA 3.0 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。

    -

    本文链接:

    +

    本文采用 CC BY-NC-SA 3.0 + 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。

    +

    本文链接:

    @@ -39,12 +72,15 @@ class="mdui-text-color-white tm-index-single-title">
    access_time - 发布时间: + 发布时间:
    access_time - 更新时间: + class="mdui-icon material-icons tm-chip-icon">update + 更新时间:
    @@ -69,6 +105,7 @@ class="mdui-ripple">分享到 Facebook
    + diff --git a/pages/page-archieve.php b/pages/page-archieve.php index cddbeb0..da0e8c2 100644 --- a/pages/page-archieve.php +++ b/pages/page-archieve.php @@ -8,7 +8,6 @@ ?> -
    @@ -30,11 +29,22 @@ class="mdui-text-color-white tm-index-single-title">
    -
    +
    + +

    +
    -

    本文采用 CC BY-NC-SA 3.0 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。

    -

    本文链接:

    +

    本文采用 CC BY-NC-SA 3.0 + 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。

    +

    本文链接:

    @@ -44,19 +54,22 @@ class="mdui-text-color-white tm-index-single-title">
    access_time - 发布时间: + class="mdui-icon material-icons tm-chip-icon">access_time + 发布时间:
    access_time - 更新时间: + class="mdui-icon material-icons tm-chip-icon">update + 更新时间:
    • @@ -85,3 +98,4 @@ class="mdui-ripple">分享到 Facebook + diff --git a/single.php b/single.php index 41156fc..bb15ba2 100644 --- a/single.php +++ b/single.php @@ -25,42 +25,38 @@ class="mdui-text-color-white tm-index-single-title">