Z-blogPHP如何实现自定义文章标题颜色?
11732023-07-06 17:55:10
以下提供一种通过过滤器插件修改文章标题颜色的方法。
1、在文章编辑增加扩展功能。
echo '<div class="editmod"><labal style="color:' . htmlspecialchars($article->Metas->titlecolor, ENT_COMPAT, 'ISO-8859-1') . ';" class="editinputname">标题颜色</labal>'; echo '<input type="text" style="width:100px;font-weight: bold;color:' . htmlspecialchars($article->Metas->titlecolor, ENT_COMPAT, 'ISO-8859-1') . ';" name="meta_titlecolor" class="input" value="' . htmlspecialchars($article->Metas->titlecolor, ENT_COMPAT, 'ISO-8859-1') . '"/></div>';
2、在include.php文件添加过滤器和封装函数
function ActivePlugin_fullpage() { //以下是过滤器代码 Add_Filter_Plugin('Filter_Plugin_ViewPost_Template', 'fullpage_ViewPost_article_titlecolor'); Add_Filter_Plugin('Filter_Plugin_ViewList_Template', 'fullpage_ViewList_article_titlecolor'); Add_Filter_Plugin('Filter_Plugin_ViewSearch_Template','fullpage_ViewSearch_article_titlecolor'); } // 文章标题颜色 function fullpage_ViewPost_article_titlecolor(&$template) { // global $zbp; $article = $template->GetTags('article'); if ($article->Metas->titlecolor) { $article->Title = "<em style='color:" . $article->Metas->titlecolor . "'>" . $article->Title . "</em>"; } $template->SetTags('article', $article); } // 首页和列表页文章标题颜色 function fullpage_ViewList_article_titlecolor($template) { // global $zbp; $articles = $template->GetTags('articles'); foreach ($articles as $article) { if ($article->Metas->titlecolor) { $article->Title = "<em style='color:" . $article->Metas->titlecolor . "'>" . $article->Title . "</em>"; } } } // 搜索页文章标题颜色 function fullpage_ViewSearch_article_titlecolor($template) { // global $zbp; $articles = $template->GetTags('articles'); foreach ($articles as $article) { if ($article->Metas->titlecolor) { $article->Title = "<em style='color:" . $article->Metas->titlecolor . "'>" . $article->Title . "</em>"; } } }
3、在文章编辑设置文章标题颜色,即可在对应的文章标题生效。
-
喜欢(12)
-
不喜欢(1)