宝宝起名主题模板

基于八字五行 · 音律字形 · 国学经典

版本 V1.0

主题简介

宝宝起名主题是一款专为起名类网站设计的逗号CMS模板,风格大气典雅,以红白为主色调,适合宝宝起名、姓名打分、老黄历查询等场景,并集成了文章展示模块。内容调用 逗号API接口,该接口由程序员配合专业姓名学老师根据用户真实输入的姓氏及生辰八字排盘计算开发完成,速度快,结果好。

核心功能

⚠️ 提示: 逗号API平台注册有赠送积分,为保证积分充足,建议充值一些积分或者推广逗号产品赚取积分,以免因积分不足无法调用! 如何获得积分?

安装步骤

  1. 下载安装主题

    安装新版逗号CMS V6.3 版本,进入后台--主题列表,选择 宝宝起名主题模板 点击免费下载安装。

  2. ⭐ 配置前端路由(重要!)

    进入后台 用户管理 → 前端路由管理,将下方路由代码复制粘贴到文本框中,点击「保存配置」。

    ⚠️ 注意: 如果未配置前端路由,起名、打分、黄历等页面将无法正常访问!

前端路由配置代码

复制下方代码,粘贴到 后台 → 用户管理 → 前端路由管理 的文本框中,点击「保存配置」即可。

前端路由代码 (PHP)
<?php
function parse_rewrite_url($uri, $setting, $db, $prefix) {
    
    if ($uri === "/" || $uri === "/index.php") {
        return "qiming_index";
    }
    
    if ($uri === "/qiming.html") {
        return "qiming_result";
    }
    
    if ($uri === "/dafen.html") {
        return "qiming_dafen";
    }
    
    if ($uri === "/laohuangli.html") {
        return "qiming_laohuangli";
    }
    
    $article_prefix = preg_quote($setting["article_prefix"] ?? "article-", "/");
    if (preg_match("/^\/" . $article_prefix . "([0-9a-zA-Z]+)\.html$/", $uri, $matches)) {
        $url_id = $matches[1];
        if ($setting["url_mode"] == 1) {
            $_GET["id"] = intval($url_id);
        } else {
            $field = ($setting["url_mode"] == 2) ? "hash_id" : "md5_id";
            $stmt = $db->prepare("SELECT id FROM {$prefix}article WHERE $field = ? LIMIT 1");
            if ($stmt) {
                $stmt->bind_param("s", $url_id);
                $stmt->execute();
                $res = $stmt->get_result();
                if ($res && $res->num_rows > 0) {
                    $row = $res->fetch_assoc();
                    $_GET["id"] = $row["id"];
                } else {
                    http_response_code(404);
                    require_once __DIR__ . "/set/404.php";
                    exit;
                }
                $stmt->close();
            } else {
                http_response_code(404);
                require_once __DIR__ . "/set/404.php";
                exit;
            }
        }
        return "article";
    }
    
    $category_prefix = preg_quote($setting["category_prefix"] ?? "category-", "/");
    if (preg_match("/^\/" . $category_prefix . "([0-9a-zA-Z]+)\.html$/", $uri, $matches)) {
        $url_id = $matches[1];
        $cat_url_mode = $setting["category_url_mode"] ?? 1;
        if ($cat_url_mode == 1) {
            $_GET["id"] = intval($url_id);
        } else {
            $field = ($cat_url_mode == 2) ? "hash_id" : "md5_id";
            $stmt = $db->prepare("SELECT id FROM {$prefix}category WHERE $field = ? LIMIT 1");
            if ($stmt) {
                $stmt->bind_param("s", $url_id);
                $stmt->execute();
                $res = $stmt->get_result();
                if ($res && $res->num_rows > 0) {
                    $row = $res->fetch_assoc();
                    $_GET["id"] = $row["id"];
                } else {
                    http_response_code(404);
                    require_once __DIR__ . "/set/404.php";
                    exit;
                }
                $stmt->close();
            } else {
                http_response_code(404);
                require_once __DIR__ . "/set/404.php";
                exit;
            }
        }
        return "category";
    }
    
    if (preg_match("/^\/product\.html$/", $uri)) {
        return "product_list";
    }
    
    $product_category_prefix = preg_quote($setting["product_category_prefix"] ?? "product-category-", "/");
    if (preg_match("/^\/" . $product_category_prefix . "([0-9a-zA-Z]+)\.html$/", $uri, $matches)) {
        $url_id = $matches[1];
        $product_cat_url_mode = $setting["product_category_url_mode"] ?? 1;
        if ($product_cat_url_mode == 1) {
            $_GET["id"] = intval($url_id);
        } else {
            $field = ($product_cat_url_mode == 2) ? "hash_id" : "md5_id";
            $stmt = $db->prepare("SELECT id FROM {$prefix}product_category WHERE $field = ? LIMIT 1");
            if ($stmt) {
                $stmt->bind_param("s", $url_id);
                $stmt->execute();
                $res = $stmt->get_result();
                if ($res && $res->num_rows > 0) {
                    $row = $res->fetch_assoc();
                    $_GET["id"] = $row["id"];
                } else {
                    http_response_code(404);
                    require_once __DIR__ . "/set/404.php";
                    exit;
                }
                $stmt->close();
            } else {
                http_response_code(404);
                require_once __DIR__ . "/set/404.php";
                exit;
            }
        }
        return "product_list";
    }
    
    $product_prefix = preg_quote($setting["product_prefix"] ?? "product-", "/");
    if (preg_match("/^\/" . $product_prefix . "([0-9a-zA-Z]+)\.html$/", $uri, $matches)) {
        $url_id = $matches[1];
        $product_url_mode = $setting["product_url_mode"] ?? 1;
        if ($product_url_mode == 1) {
            $_GET["id"] = intval($url_id);
        } else {
            $field = ($product_url_mode == 2) ? "hash_id" : "md5_id";
            $stmt = $db->prepare("SELECT id FROM {$prefix}product WHERE $field = ? LIMIT 1");
            if ($stmt) {
                $stmt->bind_param("s", $url_id);
                $stmt->execute();
                $res = $stmt->get_result();
                if ($res && $res->num_rows > 0) {
                    $row = $res->fetch_assoc();
                    $_GET["id"] = $row["id"];
                } else {
                    http_response_code(404);
                    require_once __DIR__ . "/set/404.php";
                    exit;
                }
                $stmt->close();
            } else {
                http_response_code(404);
                require_once __DIR__ . "/set/404.php";
                exit;
            }
        }
        return "product_detail";
    }
    
    if ($uri === "/list.html" || preg_match("/^\/list-([0-9]+)\.html$/", $uri, $matches)) {
        if (isset($matches[1])) $_GET["page"] = intval($matches[1]);
        return "list";
    }
    
    return "index";
}

function route_dispatch($action, $db, $prefix, $setting, $template_path) {
    
    if ($action === "qiming_index") {
        if (!isset($_GET["year"]) || !isset($_GET["month"])) {
            $_GET["year"] = date("Y");
            $_GET["month"] = date("n");
        }
        $year = intval($_GET["year"]);
        $month = intval($_GET["month"]);
        if ($month < 1) $month = 1;
        if ($month > 12) $month = 12;
        $_GET["year"] = $year;
        $_GET["month"] = $month;
        
        $seo = [
            "title" => "宝宝起名 - " . $setting["site_name"],
            "keywords" => "宝宝起名,取名,八字起名",
            "description" => "基于八字五行、音律字形、国学经典,为宝宝起个好名"
        ];
        include ROOT_PATH . "templates/qiming/header.php";
        include ROOT_PATH . "templates/qiming/index.php";
        include ROOT_PATH . "templates/qiming/footer.php";
        return true;
    }
    
    if ($action === "qiming_result") {
        $seo = [
            "title" => "宝宝起名结果 - " . $setting["site_name"],
            "keywords" => "宝宝起名,八字起名,周易起名,起名推荐",
            "description" => "基于八字五行、音律字形、国学经典,为宝宝生成吉祥好名"
        ];
        include ROOT_PATH . "templates/qiming/header.php";
        include ROOT_PATH . "templates/qiming/qiming.php";
        include ROOT_PATH . "templates/qiming/footer.php";
        return true;
    }
    
    if ($action === "qiming_dafen") {
        $seo = [
            "title" => "姓名打分 - " . $setting["site_name"],
            "keywords" => "姓名打分,名字评分,五格数理,三才配置",
            "description" => "基于五格数理、三才配置、八字五行,为姓名综合评分"
        ];
        include ROOT_PATH . "templates/qiming/header.php";
        include ROOT_PATH . "templates/qiming/dafen.php";
        include ROOT_PATH . "templates/qiming/footer.php";
        return true;
    }
    
    if ($action === "qiming_laohuangli") {
        $seo = [
            "title" => "老黄历 - " . $setting["site_name"],
            "keywords" => "老黄历,黄道吉日,择日,万年历,黄历查询",
            "description" => "提供每日黄历查询,包含宜忌、吉神凶煞、时辰吉凶等"
        ];
        include ROOT_PATH . "templates/qiming/header.php";
        include ROOT_PATH . "templates/qiming/laohuangli.php";
        include ROOT_PATH . "templates/qiming/footer.php";
        return true;
    }
    
    if ($action === "search") {
        $keyword = isset($_GET["keyword"]) ? trim($_GET["keyword"]) : "";
        if (!empty($keyword)) {
            if (!check_sensitive_words($keyword)) die("搜索内容包含敏感词");
            $keyword = str_replace(["%", "_"], ["\\%", "\\_"], $keyword);
            save_search_keyword($keyword);
            $articles = get_articles("title LIKE \"%" . $db->real_escape_string($keyword) . "%\"", 50);
        } else {
            $articles = [];
        }
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "category.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "list") {
        $page = isset($_GET["page"]) ? max(1, intval($_GET["page"])) : 1;
        $page_size = 20;
        $total = get_article_count();
        $offset = ($page - 1) * $page_size;
        $articles = get_articles("", "$offset, $page_size");
        $base_url = "/list.html?";
        $pagination = pagination($total, $page_size, $page, $base_url);
        $seo = get_seo("category", ["category_name" => "全部文章"]);
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "category.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "category") {
        $category_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $page = isset($_GET["page"]) ? max(1, intval($_GET["page"])) : 1;
        $page_size = 20;
        $category_name = "";
        $categories = get_categories();
        foreach ($categories as $cat) {
            if ($cat["id"] == $category_id) {
                $category_name = $cat["name"];
                break;
            }
        }
        if (!$category_name) {
            http_response_code(404);
            require_once __DIR__ . "/set/404.php";
            exit;
        }
        $seo = get_seo("category", ["category_name" => $category_name]);
        $where = "category_id = $category_id";
        $total = get_article_count($where);
        $offset = ($page - 1) * $page_size;
        $articles = get_articles($where, "$offset, $page_size");
        $base_url = "/" . ($setting["category_prefix"] ?? "category-") . build_url_id("category", $category_id) . ".html?";
        $pagination = pagination($total, $page_size, $page, $base_url);
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "category.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "article") {
        $id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $article = get_article($id);
        if (!$article) {
            http_response_code(404);
            require_once __DIR__ . "/set/404.php";
            exit;
        }
        update_views($id);
        $category_name = "";
        $categories = get_categories();
        foreach ($categories as $cat) {
            if ($cat["id"] == $article["category_id"]) {
                $category_name = $cat["name"];
                break;
            }
        }
        $seo = get_seo("article", [
            "article_title" => $article["title"],
            "article_description" => $article["description"] ?: mb_substr(strip_tags($article["content"]), 0, 150),
            "category_name" => $category_name
        ]);
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "article.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "product_list") {
        $category_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $page = isset($_GET["page"]) ? max(1, intval($_GET["page"])) : 1;
        $page_size = 12;
        $category_name = "全部产品";
        if ($category_id > 0) {
            $cats = $db->query("SELECT * FROM {$prefix}product_category ORDER BY sort ASC");
            while ($cat = $cats->fetch_assoc()) {
                if ($cat["id"] == $category_id) {
                    $category_name = $cat["name"];
                    break;
                }
            }
        }
        $seo = get_seo("product_list", ["category_name" => $category_name]);
        if ($category_id > 0) {
            $where = "WHERE category_id = $category_id";
            $total = $db->query("SELECT COUNT(*) as t FROM {$prefix}product $where")->fetch_assoc()["t"];
        } else {
            $where = "";
            $total = $db->query("SELECT COUNT(*) as t FROM {$prefix}product")->fetch_assoc()["t"];
        }
        $offset = ($page - 1) * $page_size;
        $products = $db->query("SELECT * FROM {$prefix}product $where ORDER BY id DESC LIMIT $offset, $page_size");
        $product_cats = $db->query("SELECT * FROM {$prefix}product_category ORDER BY sort ASC");
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "product_list.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "product_detail") {
        $id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $product = $db->query("SELECT p.*, c.name as category_name FROM {$prefix}product p LEFT JOIN {$prefix}product_category c ON p.category_id = c.id WHERE p.id = $id")->fetch_assoc();
        if (!$product) {
            http_response_code(404);
            require_once __DIR__ . "/set/404.php";
            exit;
        }
        $db->query("UPDATE {$prefix}product SET views = views + 1 WHERE id = $id");
        $gallery = json_decode($product["gallery"], true);
        if (!is_array($gallery)) $gallery = [];
        $seo = get_seo("product_detail", [
            "product_title" => $product["title"],
            "product_description" => $product["description"],
            "category_name" => $product["category_name"] ?? ""
        ]);
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "product_detail.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    if ($action === "index") {
        $seo = get_seo("index");
        $ads = get_ads(5);
        $recommend_articles = get_articles("is_recommend = 1", $seo["recommend_count"]);
        $latest_articles = get_articles("", $seo["latest_count"]);
        $latest_searches = get_latest_search(5);
        include TEMPLATE_PATH . "header.php";
        include TEMPLATE_PATH . "index.php";
        include TEMPLATE_PATH . "footer.php";
        return true;
    }
    
    return false;
}

文件结构

📁 /templates/qiming/ header.php — 页头模板 footer.php — 页脚模板 index.php — 首页内容 category.php — 文章分类列表页 article.php — 文章详情页 qiming.php — 宝宝起名结果页 dafen.php — 姓名打分页 laohuangli.php — 老黄历页 style.css — 主题全局样式 qiming.css — 起名页专属样式 dafen.css — 打分页专属样式 laohuangli.css — 黄历页专属样式 qmsm.html — 主题说明文件(当前文件)

页面URL说明

配置前端路由后,以下页面均可正常访问:

页面 URL 说明
首页 / 起名主题首页
宝宝起名 /qiming.html 起名表单及结果页
姓名打分 /dafen.html 姓名综合评分
老黄历 /laohuangli.html 每日黄历查询
全部文章 /list.html 文章列表
文章分类 /category-{id}.html 分类文章列表
文章详情 /article-{id}.html 文章内容详情

注意事项

技术支持

如在使用过程中遇到任何问题,欢迎通过以下方式联系我们:

感谢您使用逗号CMS宝宝起名主题,祝您使用愉快!