peijunlei 2 weeks ago
parent
commit
73ca6e12aa
  1. 36
      app/common.php
  2. 12
      public/themes/website/1/zh/demo/components/header.html

36
app/common.php

@ -1695,3 +1695,39 @@ if (!function_exists('getChildCategoriesContent')) {
}
}
}
// 函数名:getDescriptionSeparate (查询表 hc_category 中的字段 description 根据这个字段拆分成数组返回)
// 传入 cate_id 和 separate_str, 注意为空的判断;
if (!function_exists('getDescriptionSeparate')) {
function getDescriptionSeparate($cate_id)
{
if (empty($cate_id)) {
return [];
}
try {
$description = \think\facade\Db::table('hc_category')
->where('id', $cate_id)
->value('description');
if (empty($description)) {
return [];
}
// 使用正则提取所有以 http:// 或 https:// 开头的链接
// 匹配规则:以http(s)开头,直到遇到空白符或中文字符"分隔符"为止
preg_match_all('/https?:\/\/[^\s分隔符]+/', $description, $matches);
$result = $matches[0] ?? [];
// 过滤空值并重新索引
$result = array_filter($result, function ($value) {
return !empty(trim($value));
});
return array_values($result);
} catch (\Exception $e) {
return [];
}
}
}

12
public/themes/website/1/zh/demo/components/header.html

@ -62,7 +62,13 @@
<img src="{hcTaglib:setting name='wechat_code' type='2' /}" alt="官方微信" width="120" height="120" />
</span>
</span>
<a class="site-header__social" href="https://v.douyin.com/y7mvLjAkdJ4/" aria-label="抖音" target="_blank">
{php}
$content_arr = getDescriptionSeparate(707);
$douyin_url = $content_arr['0'] ?? '';
$sina_url = $content_arr['1'] ?? '';
$zhihu_url = $content_arr['2'] ?? '';
{/php}
<a class="site-header__social" href="{$douyin_url}" aria-label="抖音" target="_blank">
<span class="site-header__icon" aria-hidden="true">
<svg
viewBox="0 0 16 16"
@ -82,7 +88,7 @@
</svg>
</span>
</a>
<a class="site-header__social" href="https://weibo.com/u/78123456789012345678" aria-label="微博" target="_blank">
<a class="site-header__social" href="{$sina_url}" aria-label="微博" target="_blank">
<span class="site-header__icon" aria-hidden="true">
<svg
viewBox="0 0 16 16"
@ -102,7 +108,7 @@
</svg>
</span>
</a>
<a class="site-header__social" href="https://www.zhihu.com/people/78123456789012345678" aria-label="知乎" target="_blank">
<a class="site-header__social" href="{$zhihu_url}" aria-label="知乎" target="_blank">
<span class="site-header__icon" aria-hidden="true">
<svg
viewBox="0 0 16 16"

Loading…
Cancel
Save