DTcms method to get a list of articles without subclasses

Original link: https://www.feidaoboke.com/post/dtcms-get-list-not-child.html

Qihang Content Management System (DTcms) is an excellent open source website management system rarely seen in the domestic ASP.NET open source industry. Now it has been fully upgraded to ASP.NET CORE.

I have a website that uses the ASP.NET version. It has been running smoothly for a long time. For stability reasons, I will not upgrade it.

The DTcms template gets the tag of the article list on the article list page is

 get_article_list(channel,category_id, 100, "status=0")

The second parameter here is the article category ID. By default, the subcategory articles of the specified category will be returned together. Recently, Party A put forward a request to make adjustments to the article list page, and do not display the articles of its subcategory. Check the source code, It cannot be achieved by the fourth parameter, that is, by customizing the SQL condition, so we have to modify the system source code. Fortunately, it is not difficult to modify. The steps are as follows:

1. Add a get_article_list_not_child method in DTcms.Web.UI – Label – article.cs, which is also the reference label in the template file. The code is as follows:

 protected DataTable get_article_list_not_child(string channel_name, int category_id, int top, string strwhere) { DataTable dt = new DataTable(); if (!string.IsNullOrEmpty(channel_name)) { dt = new BLL.article().ArticleListNotChild(channel_name, category_id, top, strwhere, "sort_id asc,add_time desc").Tables[0]; } return dt; }

2. Add the ArticleListNotChild method in the DTcms.BLL – article.cs file, the code is as follows:

 public DataSet ArticleListNotChild(string channel_name, int category_id, int Top, string strWhere, string filedOrder) { Dictionary<int, string> dic = new BLL.site_channel().GetListAll(); if (!dic.ContainsValue(channel_name)) { return new DataSet(); } return dal.ArticleListNotChild(channel_name, category_id, Top, strWhere, filedOrder); }

3. Add the ArticleListNotChild method in the DTcms.DAL – article.cs file, the code is as follows:

 public DataSet ArticleListNotChild(string channel_name, int category_id, int Top, string strWhere, string filedOrder) { Dictionary<int, string> dic = new BLL.site_channel().GetListAll(); if (!dic.ContainsValue(channel_name)) { return new DataSet(); } return dal.ArticleListNotChild(channel_name, category_id, Top, strWhere, filedOrder); }

4. Compile and generate the three modified projects (DTcms.DAL, DTcms.BLL, DTcms.Web.UI) in turn in the DTcms source code solution, and the compilation order cannot be reversed.

5. Replace the generated dll with the corresponding three dll files (DTcms.DAL.dll, DTcms.BLL.dll and Dtcms.Web.UI.dll) in the bin folder of the deployment project DTcms.Web project.

6. Modify the article list file of the template, and set the new label in the place where you want to get the article list. The configuration parameters are the same as the labels that come with the system, except that the subcategory articles of the specified category will no longer be found. I am here to get The status under the current category is the first 100 articles published, and the tag code is as follows:

 get_article_list_not_child(channel,category_id, 100, "status=0")

If any readers and friends encounter problems when modifying the code with reference to this article, they can contact me by email (the email address is on the About page of this blog).

This article is reprinted from: https://www.feidaoboke.com/post/dtcms-get-list-not-child.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment