dede_arctype是什么?如何使用?

99ANYc3cd6
预计阅读时长 28 分钟
位置: 首页 DEDE建站 正文

Of course! Let's break down dede_arctype in detail. It's one of the most important tables in the DedeCMS (织梦内容管理系统) database.

dede dede_arctype
(图片来源网络,侵删)

What is dede_arctype?

In simple terms, dede_arctype is the database table that stores all the "channel" or "category" information in DedeCMS.

Think of it as the backbone or the blueprint for your website's structure. Every section or folder you create in your DedeCMS backend (e.g., "News," "Products," "About Us," "Gallery") corresponds to a record in this table.


What are its main purposes?

The dede_arctype table serves several critical functions:

  1. Content Organization: It's the primary way to organize your website's content into a logical hierarchy. You can have main categories (like "News") and sub-categories (like "News -> Technology News").
  2. Navigation Generation: It provides the data for automatically generating your website's navigation menus (like the main menu, footer links, or breadcrumb trails).
  3. Content Filtering: It allows you to filter and display content from specific categories on different pages of your website. For example, you can have a page that only shows articles from the "Product Reviews" category.
  4. URL Structure: It plays a key role in defining the URL of your category pages (e.g., yourdomain.com/news/ or yourdomain.com/products/).
  5. Template Logic: In DedeCMS's template engine (dedecms tags), you use this table to loop through and display categories.

Important Fields in the dede_arctype Table

Here is a list of the most common and important fields you will find in this table. Understanding them is key to customizing your DedeCMS site.

dede dede_arctype
(图片来源网络,侵删)
Field Name (Chinese) Field Name (English) Description & Common Use
id ID Primary Key. A unique number for each category. Used for internal referencing.
reid Parent ID The ID of the parent category. If reid is 0, it's a top-level (main) category. Otherwise, it's a sub-category of the category with the ID in reid.
topid Top-level ID The ID of the top-most parent category in its hierarchy. Useful for breadcrumb trails.
sortrank Sort Order An integer used to control the order of categories. A lower number means it appears first (e.g., in a navigation menu). You can sort by this field in ascending order.
typename Category Name Crucial. The public name of the category (e.g., "公司新闻", "产品中心"). This is what users see.
typedir Category Directory Crucial. The folder name for this category on the server. Used to build the URL. e.g., /news/, /products/.
isdefault Is Default? Specifies if this category is the default channel for the site. Usually 0 or 1.
defaultname Default Page Name The filename of the default list page for this category (e.g., index.html).
issend Allow Submission? 0 or 1. Determines if users can submit content to this category (often used for member contributions).
channeltype Channel Type Defines the type of content this category holds. 1 for article, 2 for image gallery, etc.
moresite Multi-site? 0 or 1. Used for multi-site functionality in DedeCMS.
description Description A short description of the category, often used for SEO.
keywords Keywords SEO keywords for the category.
seotitle SEO Title A custom title for SEO, overriding the default page title.
modulus` Template ID Links to a specific template style for this category.
ishidden Is Hidden? 0 or 1. If 1, the category is hidden from navigation menus but can still be used internally.

How is dede_arctype used in Practice?

A. In the DedeCMS Backend (Admin Panel)

When you go to "核心 -> 单页文档管理 ->频道管理" (Core -> Single Page Document Management -> Channel Management), you are essentially viewing and editing the records in the dede_arctype table.

  • Adding a Category: You fill out a form with the typename, typedir, sortrank, etc., and a new record is inserted into the table.
  • Editing a Category: You modify the fields for an existing record.
  • Deleting a Category: You delete a record. Warning: Deleting a category with sub-categories or content can cause data loss if not handled properly.

B. In PHP Code (Direct Database Query)

If you are a developer, you might query this table directly to get a list of categories.

Example: Get all top-level categories, ordered by their sort order.

<?php
require_once(dirname(__FILE__)."/include/config_base.php");
require_once(DEDEINC."/typelink.class.php");
// Connect to the database
$dsql = new DedeSql(false);
// SQL Query to get top-level categories (reid = 0)
$sql = "SELECT id, typename, typedir FROM `dede_arctype` WHERE reid = 0 ORDER BY sortrank ASC";
$dsql->SetQuery($sql);
$dsql->Execute();
// Loop through the results
while ($row = $dsql->GetArray()) {
    echo "Category ID: " . $row['id'] . "<br>";
    echo "Name: " . $row['typename'] . "<br>";
    echo "Directory: " . $row['typedir'] . "<br>";
    echo "-------------------------<br>";
}
?>

C. In DedeCMS Templates (Using Dede Tags)

This is the most common way it's used. You use the {dede:channel} tag to loop through categories and display them.

dede dede_arctype
(图片来源网络,侵删)

Example: Create a main navigation menu.

<ul id="main-nav">
    <li><a href="{dede:global.cfg_cmsurl/}/">首页</a></li>
    {dede:channel type='top' row='8'}
    <li>
        <a href="[field:typelink/]">[field:typename/]</a>
        <!-- You can add sub-category logic here if needed -->
    </li>
    {/dede:channel}
</ul>

Explanation of the template tags:

  • {dede:channel type='top' row='8'}: This is the main loop.
    • type='top': Tells DedeCMS to only fetch categories where reid = 0 (the main, top-level categories).
    • row='8': Limits the output to the first 8 categories found.
  • [field:typelink/]: This is a special field that automatically generates the full URL for the category, combining the site's base URL with the typedir field (e.g., http://yourdomain.com/news/).
  • [field:typename/]: Outputs the public name of the category from the typename field.

Relationship with Other Tables

dede_arctype doesn't exist in a vacuum. It's linked to other core tables:

  • dede_archives: This table holds all your articles, pages, and other content items. Crucially, it has a typeid field that links back to the id field in dede_arctype. This is how you know which piece of content belongs to which category.
  • dede_arctype (itself): The reid and topid fields create a self-referencing relationship, allowing for nested category structures.
  • dede_channeltype: The channeltype field in dede_arctype references this table to determine what kind of content model the category uses (article, image, etc.).

Summary

Concept Description
What it is The database table for all categories/channels in DedeCMS.
Why it's important It structures your site, generates navigation, and filters content.
Key Fields id, reid (parent), typename (name), typedir (URL folder), sortrank (order).
How to use it Via the backend, direct PHP queries, or (most commonly) with the {dede:channel} template tag.
Main Relationship Links to dede_archives via the typeid field to categorize content.
-- 展开阅读全文 --
头像
织梦tag标签管理模板不存在怎么办?
« 上一篇 2025-12-19
零基础学C Primer,能直接上手吗?
下一篇 » 2025-12-19

相关文章

取消
微信二维码
支付宝二维码

目录[+]