feat(pages): 1:1 文章导航 posts-navs (zibll postsnavs)
Per-category full post lists, affix TOC shell, admin drag-sort settings modal + AJAX save (navs_show_cat_id / name / desc).
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* 文章导航页设置 AJAX(zibll action/post_navs.php parity).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Core;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class PostsNavs {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
add_action('wp_ajax_aksrt_post_navs_settings', [$this, 'ajax_save_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Super-admin only: save navs_page_name / desc / ordered cat IDs.
|
||||
*/
|
||||
public function ajax_save_settings(): void {
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json(['error' => 1, 'ys' => 'danger', 'msg' => __('权限不足', 'aksrt')]);
|
||||
}
|
||||
if (!check_ajax_referer('aksrt_post_navs_settings', '_wpnonce', false)) {
|
||||
wp_send_json(['error' => 1, 'ys' => 'danger', 'msg' => __('安全校验失败', 'aksrt')]);
|
||||
}
|
||||
|
||||
$page_id = isset($_POST['page_id']) ? absint($_POST['page_id']) : 0;
|
||||
if ($page_id <= 0 || get_post_type($page_id) !== 'page') {
|
||||
wp_send_json(['error' => 1, 'ys' => 'danger', 'msg' => __('无效页面', 'aksrt')]);
|
||||
}
|
||||
|
||||
$cat_ids = [];
|
||||
if (isset($_POST['navs_show_cat_id'])) {
|
||||
$raw = wp_unslash($_POST['navs_show_cat_id']);
|
||||
if (is_array($raw)) {
|
||||
$cat_ids = array_values(array_filter(array_map('intval', $raw)));
|
||||
} elseif (is_string($raw) && $raw !== '') {
|
||||
$decoded = json_decode($raw, true);
|
||||
if (is_array($decoded)) {
|
||||
$cat_ids = array_values(array_filter(array_map('intval', $decoded)));
|
||||
} else {
|
||||
$cat_ids = array_values(array_filter(array_map('intval', explode(',', $raw))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($cat_ids)) {
|
||||
wp_send_json(['error' => 1, 'ys' => 'danger', 'msg' => __('请选择需要显示的分类', 'aksrt')]);
|
||||
}
|
||||
|
||||
if (isset($_POST['navs_page_name'])) {
|
||||
update_post_meta($page_id, 'navs_page_name', sanitize_text_field(wp_unslash((string) $_POST['navs_page_name'])));
|
||||
}
|
||||
if (isset($_POST['navs_page_desc'])) {
|
||||
update_post_meta($page_id, 'navs_page_desc', sanitize_text_field(wp_unslash((string) $_POST['navs_page_desc'])));
|
||||
}
|
||||
update_post_meta($page_id, 'navs_show_cat_id', $cat_ids);
|
||||
|
||||
wp_send_json([
|
||||
'error' => 0,
|
||||
'msg' => __('保存成功', 'aksrt'),
|
||||
'reload'=> true,
|
||||
'ids' => $cat_ids,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -404,6 +404,39 @@ trait ScriptsPart1b {
|
||||
}
|
||||
}
|
||||
|
||||
// 文章导航页(zibll postsnavs.php)
|
||||
if (is_page_template('templates/pages/page-posts-navs.php')) {
|
||||
$pn_css = get_template_directory() . '/assets/css/routes/posts-navs.css';
|
||||
if (file_exists($pn_css)) {
|
||||
wp_enqueue_style(
|
||||
'aksrt-route-posts-navs',
|
||||
$base_uri . '/assets/css/routes/posts-navs.css',
|
||||
['aksrt-tokens'],
|
||||
(string) filemtime($pn_css)
|
||||
);
|
||||
}
|
||||
$section_navs = get_template_directory() . '/assets/js/section-navs.js';
|
||||
if (file_exists($section_navs)) {
|
||||
wp_enqueue_script(
|
||||
'aksrt-section-navs',
|
||||
$base_uri . '/assets/js/section-navs.js',
|
||||
['jquery'],
|
||||
(string) filemtime($section_navs),
|
||||
true
|
||||
);
|
||||
}
|
||||
$pn_js = get_template_directory() . '/assets/js/posts-navs-page.js';
|
||||
if (file_exists($pn_js)) {
|
||||
wp_enqueue_script(
|
||||
'aksrt-posts-navs-page',
|
||||
$base_uri . '/assets/js/posts-navs-page.js',
|
||||
['jquery'],
|
||||
(string) filemtime($pn_js),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 交易中心共享壳层(购物车 / 订单 / 收益)
|
||||
$is_commerce_center = is_page_template('templates/pages/page-orders.php')
|
||||
|| is_page_template('templates/pages/page-cart.php')
|
||||
|
||||
Reference in New Issue
Block a user