Home > CMS Tutorial > DEDECMS > How to obtain the sub-column of Dedecms

How to obtain the sub-column of Dedecms

藏色散人
Release: 2020-01-07 09:08:44
Original
2066 people have browsed it

How to obtain the sub-column of Dedecms

How to obtain the dedecms sub-column?

dedecms5.7 Get the label of the top column name

Recommended learning: 梦Weavercms

The following is the method of calling the top column name :

Method 1:

{dede:field.typeid runphp=’yes’}$ID = @me; 
$sql = “SELECT * FROM `dede_arctype` WHERE id=$ID”;
$query = mysql_query($sql);$row=mysql_fetch_array($query); 
$relID = “$row[reid]“; if($relID == 0) {@me = $row[typename];}
else{$sql = “SELECT `typename` FROM `dede_arctype` WHERE id=$relID”;
$query = mysql_query($sql);$row=mysql_fetch_array($query); 
@me = $row[typename];}{/dede:field.typeid}
Copy after login

This method statement is a bit long.

Method 2:

{dede:field.title  runphp='yes'}
list($toptype,$sontype)=split('/',@me);@me=$toptype;
{/dede:field.title}
Copy after login

Method 3:

{dede:field.typeid runphp='yes'}
$ID = @me; $sql = "SELECT * FROM `dede_arctype` WHERE id=$ID";
$query = mysql_query($sql);$row=mysql_fetch_array($query); 
$relID = "$row[reid]"; $topID="$row[topid]"; 
if($relID == 0) {@me = $row[typename];}
else{$sql = "SELECT `typename` FROM `dede_arctype` WHERE id=$topID";
$query = mysql_query($sql);$row=mysql_fetch_array($query); 
@me = $row[typename];}{/dede:field.typeid}
Copy after login

Method 4 (recommended):

Open include/helpers/extend.helper.php and add A function:

/**
 *  获取指定栏目id的顶级栏目的名称
 *
 * @return     string
 */
if ( ! function_exists('getTopChannelName'))
{
function getTopChannelName($id) {
   global $dsql;
        $typeinfo = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id='{$id}'");
        if($typeinfo['reid']==0) return $typeinfo['typename'];
        else return getTopChannelName($typeinfo['reid']);
}
}
Copy after login

Use it like this on the list page: {dede:field name='id' function='getTopChannelName(@me)'/}

Use it like this on the content page: {dede :field name='typeid' function='getTopChannelName(@me)'/}

Attached is to get the url of the top column:

Open include/helpers/extend.helper.php and add one Function:

/**
 *  获取指定栏目id的顶级栏目的url
 *
 * @return     string
 */
if ( ! function_exists('getTopChannelUrl'))
{
function getTopChannelUrl($id) {
   global $dsql;
        $typeinfo = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id='{$id}'");
        if($typeinfo['reid']==0) return GetOneTypeUrlA($typeinfo);
        else return getTopChannelUrl($typeinfo['reid']);
}
}
Copy after login

Usage method is the same as above.

The above is the detailed content of How to obtain the sub-column of Dedecms. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template