Of course! This is a very common question for developers working with DedeCMS (织梦内容管理系统). Let's break down what dede:myad is and the clsid attribute in detail.
What is dede:myad?
dede:myad is a custom tag specific to DedeCMS. It's used within the DedeCMS template engine to display advertisements (ads) that have been uploaded and managed through the DedeCMS backend.
Think of it as a shortcut or a placeholder in your HTML template that tells DedeCMS: "At this spot, insert the code for the specific ad I've configured."
How it Works:
- Upload Ad in Backend: An administrator logs into the DedeCMS admin panel (
/dede/) and goes to 核心 -> 广告管理 (Core -> Ad Management). They can create a new ad, give it a name, and upload the ad content (e.g., an image, HTML code, or JavaScript). - Assign an Ad ID: Each ad is automatically assigned a unique numeric ID (e.g., Ad ID 1, Ad ID 2).
- Use the Tag in Template: In your template file (
.htm), you use thedede:myadtag to call that specific ad by its ID.
What is the clsid Attribute?
The clsid attribute is a parameter you use with the dede:myad tag to specify which ad you want to display.
clsidis the parameter name. It's fixed.- The value of
clsidis the numeric ID of the ad you created in the DedeCMS backend.
So, clsid='1' means "Display the ad with ID 1".
Syntax and Examples
The basic syntax of the tag is:
{dede:myad clsid='YourAdID'/}
Example 1: Displaying a Specific Ad
Let's say in your DedeCMS backend, you created an ad named "首页顶部横幅" (Homepage Top Banner) and it was assigned the ID 3.
To display this ad on your homepage, you would use this tag in your index.htm template:
<!-- This will display the ad with ID 3 -->
{dede:myad clsid='3'/}
When DedeCMS renders this page, it will replace {dede:myad clsid='3'/} with the actual code for that ad (e.g., an <img> tag or a <script> tag).
Example 2: Displaying Multiple Ads
You can use the tag multiple times on the same page to display different ads.
<!-- Top Banner (Ad ID 3) -->
<div class="top-banner">
{dede:myad clsid='3'/}
</div>
<!-- Sidebar Skyscraper (Ad ID 5) -->
<div class="sidebar-ad">
{dede:myad clsid='5'/}
</div>
Common Problems and Troubleshooting
If your dede:myad tag isn't working, here are the most likely causes:
Problem 1: Incorrect clsid Value
- Symptom: The ad space is completely blank.
- Cause: You might have mistyped the ID or are using an ID that doesn't exist.
- Solution:
- Go to 核心 -> 广告管理 in your DedeCMS backend.
- Find the ad you want to use and look at its ID in the list.
- Double-check that the
clsidvalue in your template matches this ID exactly.
Problem 2: The Ad is Disabled or Expired
- Symptom: The ad space is blank.
- Cause: The ad might be set to "未启用" (Not Enabled) or its "过期时间" (Expiration Date) might have passed.
- Solution:
- Go to the ad in 广告管理.
- Check that the "状态" (Status) is "启用" (Enabled).
- Check the "过期时间" (Expiration Time) field. If it's set, make sure the current date is before that date.
Problem 3: Caching Issues
- Symptom: The old ad is still showing even after you've changed the
clsidor updated the ad content. - Cause: DedeCMS heavily uses caching. The template file itself might be cached.
- Solution:
- Go to 系统 -> 站点设置 -> 性能选项 (System -> Site Settings -> Performance Options).
- Click the "更新主页HTML" (Update Homepage HTML) button. This will regenerate the homepage and clear its cache.
- If it's a channel page, go to that channel's management page and perform a similar update.
Problem 4: File Permissions
- Symptom: The ad space is blank or you get an error.
- Cause: The web server user (like
www-dataorapache) might not have permission to write to the cache or data directories. - Solution:
- Check the permissions of the
/dataand/templets/cachedirectories. - They should typically be writable by the web server (e.g.,
chmod 777 /dataorchown www-data:www-data /data).
- Check the permissions of the
Alternative Parameters for dede:myad
Besides clsid, the tag supports other useful parameters:
| Parameter | Description | Example |
|---|---|---|
typeid |
(Deprecated) Used in older versions. Use clsid now. |
typeid='1' |
channelid |
The channel ID where the ad is located. Usually 0 for ads. |
channelid='0' |
cache |
Enables caching for the ad, improving performance. | cache='yes' |
name |
The name of the ad. This is not the ID. It's for reference. | name='首页顶部横幅' |
Important: The name parameter is generally not used for calling the ad. The standard and most reliable way is to use the clsid with the ad's numeric ID.
Summary
| Term | Meaning | Example |
|---|---|---|
dede:myad |
The DedeCMS template tag for displaying an ad. | {dede:myad ... /} |
clsid |
The attribute that specifies which ad to show. | clsid='3' |
clsid='3' |
The full tag to display the ad with the ID of 3. |
{dede:myad clsid='3'/} |
