当前位置:首页 > 行业动态 > 正文

如何在DedeCMS中设置文章标题前显示所属栏目名称?

在DedeCMS中,要在文章名前面显示所属的文章栏目,可以通过修改模板文件来实现。具体操作如下:,,1. 打开 DedeCMS的后台管理界面,找到“模板”选项,点击进入。,2. 在模板列表中找到需要修改的模板文件,list_article.htm”(文章列表模板)。,3. 编辑模板文件,找到需要显示文章标题的位置,添加以下代码:,,“ html,{dede:field name='typeid' function='GetTopTypeName(@me)'/},“,,4. 保存修改后的模板文件,然后更新缓存。,,这样,在文章列表中,每个 文章标题前都会显示所属的文章栏目名称。

在dedecms中,要在文章名前面显示所属的文章栏目,可以通过使用标签和代码实现,以下是具体操作步骤:

1、调用栏目名称和链接

方法一:通过修改模板文件,直接在文章标题前添加栏目名称和链接。

打开对应的文章列表模板文件(例如article_article.htm)。

在文章标题前插入以下代码:

       [field:typelink/]<a href="[field:arcurl/]" target=_blank>[field:title/]</a>

方法二:通过修改系统文件,增加对栏目名称的调用。

打开include/inc_archives_view.php 文件。

查找并替换tp.typedir 为tp.typedir,tp.typename。

在文章模板中使用{dede:field name='typename'/} 调用栏目名称。

2、调整栏目名称显示格式

在首页或列表页显示:可以在首页或列表页的模板文件中,通过{dede:arclist} 标签调用文章列表时,添加栏目名称。

示例代码:

       {dede:arclist typeid='' row='' col='' titlelen='' infolen='' imgwidth='' imgheight='' listtype='' orderby='pubdate' keyword='' limit='0,1'}
         <li typeid='[field:typeid/]'><a href='[field:typelink/]'>[field:typename/]</a> [field:title/]</li>
       {/dede:arclist}

3、处理多级栏目

对于包含多级栏目的网站,可以使用以下代码来生成完整的栏目路径:

     $tc = ""; //分隔符
     $tw = $GLOBALS['cfg_list_symbol']; //位置分隔符
     $tf = explode(",",$tw);
     $me = @mee(); //运行php
     $tk = $GLOBALS['cfg_list_symbol']; //位置分隔符
     if($me){
         $tc = ""; $tw=$GLOBALS['cfg_list_symbol'];
         $tf = explode(",",$tw);
         $@me = "";
         for ($ta=count($tf)2; $ta>=1; $ta){
             $trim = trim($tf[$ta]);
             $tk .= $trim;
         }
         $tk = substr($tk, 0, 1);
         $@me = $@me . $tk;
         $me = &mee();
     } else {
         $@me = "";
     }
     $@me = str_replace("4级栏目3级栏目2级栏目","",$@me);
     $@me = str_replace("4级栏目3级栏目","",$@me);
     $@me = str_replace("4级栏目","",$@me);
     $@me = str_replace("3级栏目","",$@me);
     $@me = str_replace("2级栏目","",$@me);
     $@me = str_replace("1级栏目","",$@me);
     $@me = str_replace("网站名","",$@me);
     $@me = str_replace(""," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@me = str_replace("  "," ",$@me);
     $@m = @mee();
     $@m = str_replace("网站名","",$@m);
     $@m = str_replace(""," >",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$@m);
     $@m = str_replace("  "," ",$0me);
     $0me = $0me . '<br />';
     echo $0me;

这段代码通过递归的方式生成了完整的栏目路径,并将其添加到文章标题之前。

Faqs:

1、如何在首页显示文章所属的栏目?

如果希望在首页或其他列表页面显示每篇文章所属的栏目,可以在相应的列表模板中添加类似的代码片段,在{dede:arclist}标签内使用[field:typelink/]和[field:typename/]字段。

2、如何确保栏目链接正确生成?

确保在后台正确设置栏目的链接方式(如绝对链接、相对链接等),并在生成栏目链接时使用正确的字段,如[field:typelink/]。

3、如何处理多语言网站的栏目显示问题?

对于多语言网站,可以在不同的语言模板文件中分别添加上述代码,或者使用多语言支持插件来自动处理栏目名称的翻译。

步骤 描述 代码示例
1. 确定栏目ID 在文章内容中,首先需要获取到文章所属的栏目ID。
2. 获取栏目名称 使用栏目ID获取栏目名称。
3. 显示栏目名称 在文章标题前显示所属栏目名称。
4. 完整代码示例 将以上步骤整合到完整的代码中。 `

// 获取文章ID

$arcID = $arcRow[‘id’];

// 获取栏目ID

$catid = GetCategory($arcID);

// 获取栏目名称

$typename = $arcRow[‘typename’];

// 显示栏目名称和文章标题

echo ‘<span >’ . $typename . ‘</span> ‘ . $arcRow[‘title’];

?>` |

步骤和代码示例展示了如何在DedeCMS中在文章名前面显示所属的文章栏目,具体的代码可能需要根据您的网站结构和模板进行调整。

0