v1.7 — 登录态 + 评论优化
- 隐藏 WP admin bar - 导航栏右侧登录用户头像+姓名下拉菜单 - 笺文评论:只显示输入框+按钮,未登录点提交提示登录 - 评论无需审核直接显示
This commit is contained in:
+33
-10
@@ -40,16 +40,39 @@ if (post_password_required()) return;
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
comment_form(array(
|
||||
'title_reply' => '笺下留言',
|
||||
'title_reply_before' => '<h3 class="comment-reply-title">',
|
||||
'title_reply_after' => '</h3>',
|
||||
'comment_notes_before' => '',
|
||||
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
|
||||
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
|
||||
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
||||
'label_submit' => '落笔留痕',
|
||||
));
|
||||
if (is_user_logged_in()) :
|
||||
// 登录后:只显示留言框 + 按钮,隐藏 "Logged in as XXX"
|
||||
comment_form(array(
|
||||
'title_reply' => '笺下留言',
|
||||
'title_reply_before' => '<h3 class="comment-reply-title">',
|
||||
'title_reply_after' => '</h3>',
|
||||
'comment_notes_before' => '',
|
||||
'comment_notes_after' => '',
|
||||
'logged_in_as' => '',
|
||||
'fields' => array(),
|
||||
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
|
||||
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
|
||||
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
||||
'label_submit' => '落笔留痕',
|
||||
));
|
||||
else :
|
||||
// 未登录:只显示输入框 + 按钮,提交时提示登录
|
||||
?>
|
||||
<h3 class="comment-reply-title">笺下留言</h3>
|
||||
<form id="commentform-guest" class="comment-form" novalidate>
|
||||
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
|
||||
<div class="form-submit">
|
||||
<button type="submit" class="submit">落笔留痕</button>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
if (confirm('请先登录')) {
|
||||
window.location.href = '/wp-login.php';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -122,6 +122,9 @@ remove_action('admin_print_styles', 'print_emoji_styles');
|
||||
|
||||
add_filter('emoji_svg_url', '__return_false');
|
||||
|
||||
// 隐藏顶部 admin bar
|
||||
add_filter('show_admin_bar', '__return_false');
|
||||
|
||||
// 评论表单中文化
|
||||
add_filter('comment_form_default_fields', function($fields) {
|
||||
$fields['author'] = '<p class="comment-form-author"><label for="author">显示名称</label><input id="author" name="author" type="text" size="30" /></p>';
|
||||
@@ -131,6 +134,9 @@ add_filter('comment_form_default_fields', function($fields) {
|
||||
return $fields;
|
||||
});
|
||||
|
||||
// 评论无需审核直接发布
|
||||
add_filter('pre_comment_approved', function() { return 1; });
|
||||
|
||||
add_action('template_include', function($template) {
|
||||
if (get_query_var('post_type') === 'post' && !is_home() && !is_singular()) {
|
||||
$t = locate_template('archive.php');
|
||||
|
||||
+51
-18
@@ -15,24 +15,57 @@
|
||||
<a href="/" class="logo-area">
|
||||
<span class="logo"><?php bloginfo('name'); ?></span>
|
||||
</a>
|
||||
<nav>
|
||||
<?php
|
||||
if (has_nav_menu('primary')) {
|
||||
wp_nav_menu(array(
|
||||
'theme_location' => 'primary',
|
||||
'container' => false,
|
||||
'menu_class' => 'nav-links',
|
||||
'depth' => 1,
|
||||
));
|
||||
} else {
|
||||
echo '<ul class="nav-links">';
|
||||
echo '<li><a href="/">首页</a></li>';
|
||||
echo '<li><a href="/articles/">笺文</a></li>';
|
||||
echo '<li><a href="/tucao/">微言</a></li>';
|
||||
echo '<li><a href="/photos/">拾影</a></li>';
|
||||
echo '</ul>';
|
||||
}
|
||||
<div class="top-bar-right">
|
||||
<nav>
|
||||
<?php
|
||||
if (has_nav_menu('primary')) {
|
||||
wp_nav_menu(array(
|
||||
'theme_location' => 'primary',
|
||||
'container' => false,
|
||||
'menu_class' => 'nav-links',
|
||||
'depth' => 1,
|
||||
));
|
||||
} else {
|
||||
echo '<ul class="nav-links">';
|
||||
echo '<li><a href="/">首页</a></li>';
|
||||
echo '<li><a href="/articles/">笺文</a></li>';
|
||||
echo '<li><a href="/tucao/">微言</a></li>';
|
||||
echo '<li><a href="/photos/">拾影</a></li>';
|
||||
echo '</ul>';
|
||||
}
|
||||
?>
|
||||
</nav>
|
||||
<?php if (is_user_logged_in()) :
|
||||
$current_user = wp_get_current_user();
|
||||
?>
|
||||
</nav>
|
||||
<div class="user-menu">
|
||||
<button class="user-menu-trigger" type="button" aria-haspopup="true">
|
||||
<?php echo get_avatar($current_user->ID, 28); ?>
|
||||
<span class="user-menu-name"><?php echo esc_html($current_user->display_name); ?></span>
|
||||
<span class="user-menu-arrow">▾</span>
|
||||
</button>
|
||||
<div class="user-menu-dropdown">
|
||||
<a href="/author/<?php echo esc_attr($current_user->user_nicename); ?>/" rel="nofollow">个人资料</a>
|
||||
<a href="/wp-admin/" rel="nofollow">系统后台</a>
|
||||
<a href="/wp-login.php?action=logout" rel="nofollow">退出</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
<script>
|
||||
(function(){
|
||||
var trigger = document.querySelector('.user-menu-trigger');
|
||||
var menu = document.querySelector('.user-menu');
|
||||
if (trigger && menu) {
|
||||
trigger.addEventListener('click', function(e) {
|
||||
e.stopPropagation();
|
||||
menu.classList.toggle('open');
|
||||
});
|
||||
document.addEventListener('click', function() {
|
||||
menu.classList.remove('open');
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<div class="main-content">
|
||||
|
||||
Reference in New Issue
Block a user