Home >CMS Tutorial >DEDECMS >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}
This method statement is a bit long.
Method 2:
{dede:field.title runphp='yes'} list($toptype,$sontype)=split('/',@me);@me=$toptype; {/dede:field.title}
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}
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']); } }
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']); } }
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!