Dedecms 5.6/5.7 add weight sorting by weight summary

Source: Internet
Author: User
Tags abs ereg php file rand

DEDECMS has a weight value in the background, and you will be prompted that the smaller the weight, the higher the ranking of the article, but what makes people think is that in the old version and new version of DEDE, there is no related label to call this sort method. We can only modify it ourselves to achieve the desired effect.

I. {dede: list} added a weight-based sorting label on the v5.6 list page of Zhimeng

The weight field has been added to Zhimeng v5.6 and can be used by default in the {dede: arclist tag. However, the label {dede: list on the list page still cannot be sorted by weight. In fact, the solution is very simple. The following describes the solution:

1. Find the arclist. lib. Php file in the/include/taglib directory in the Zhimeng system and open it, because we need to copy the code from it;

2. Search for "document sorting method" in the file opened above and find the following code:

The code is as follows: Copy code

Else if ($ orderby = 'weight ') $ ordersql = "order by arc. weight asc"; // Sort by weight first if no specific settings are specified.

3. Copy the code, open the arc. listview. class. Php file in the/include/directory, search for "sorting method", and

The code is as follows: Copy code

Else if ($ orderby = "lastpost "){
$ Ordersql = "order by arc. lastpost $ orderWay ";
} This code and

Else {
$ Ordersql = "order by arc. sortrank $ orderWay ";
}

Paste the copied code in the middle of the code.

4. Find if (ereg ('hot | click | lastpost', $ orderby) and change it to if (ereg ('hot | click | lastpost | weight ', $ orderby) to save the file.

In this case, you can use {dede: list pagesize = '5 & prime; orderby = 'weight'} in the list page for sorting.

II. DEDE 5.7 homepage [arclist] adds weight-based sorting

1. Find the arclist. lib. Php file in the/include/taglib directory in the Zhimeng system and open

Found in lines 74 and 75:

The code is as follows: Copy code

// Whether weight sorting is required for arclist. The default value is "N". If sorting is required, it is set to "Y"
$ Isweight = $ ctag-> GetAtt ('isight ');

Modify this line:

$ Weight = $ ctag-> GetAtt ('weight ');

Found in approximately 327 rows

The code is as follows: Copy code

// Document sorting method
$ Ordersql = ";
If ($ orderby = 'Hot '| $ orderby = 'click') $ ordersql = "order by arc. click $ orderWay ";
Else if ($ orderby = 'sortrank' | $ orderby = 'pubdate') $ ordersql = "order by arc. sortrank $ orderWay ";
Else if ($ orderby = 'id') $ ordersql = "order by arc. id $ orderWay ";
Else if ($ orderby = 'near ') $ ordersql = "order by abs (arc. id-". $ arcid .")";
Else if ($ orderby = 'lastpost') $ ordersql = "order by arc. lastpost $ orderWay ";
Else if ($ orderby = 'scores') $ ordersql = "order by arc. scores $ orderWay ";
Else if ($ orderby = 'Rand') $ ordersql = "order by rand ()";
Else $ ordersql = "order by arc. sortrank $ orderWay ";

To:

The code is as follows: Copy code

// Document sorting method
$ Ordersql = ";
If ($ orderby = 'Hot '| $ orderby = 'click') $ ordersql = "order by arc. click $ orderWay ";
Else if ($ orderby = 'sortrank' | $ orderby = 'pubdate') $ ordersql = "order by arc. sortrank $ orderWay ";
Else if ($ orderby = 'id') $ ordersql = "order by arc. id $ orderWay ";
Else if ($ orderby = 'near ') $ ordersql = "order by abs (arc. id-". $ arcid .")";
Else if ($ orderby = 'lastpost') $ ordersql = "order by arc. lastpost $ orderWay ";
Else if ($ orderby = 'scores') $ ordersql = "order by arc. scores $ orderWay ";
Else if ($ orderby = 'Rand') $ ordersql = "order by rand ()";
Else if ($ orderby = 'weight ') $ ordersql = "order by arc. weight asc"; // Sort by weight first if no specific settings are specified.
Else $ ordersql = "order by arc. sortrank $ orderWay ";

OK. Now we have saved this document. We can use the orderby = 'weight' label on the homepage or other pages to sort the document by weight.


After 5.6, DEDE added the weight sorting function of the article. However, many children's shoes adjusted the weight value and added orderby = 'weight' to the arclist label, but found no effect.

The reason is that this function is disabled by default.

The jar contains related solutions. You need to change arclist. lib. php to use this function.

In fact, it is completely unnecessary. The correct method of use is as follows:

The code is as follows: Copy code

{Dede: arclist titlelen = '38' flag = 'h' noflag = 'a' isweight = 'y' orderby = 'weight '}

<Li> <span> [[field: typelink/] </span> <a href = "[field: arcurl/]"> [field: title/] </a> <div class = "c2time"> [field: pubdate function = MyDate ('Y-m-D', @ me) /] </div> </li>

{/Dede: arclist}

The red part is to enable weight sorting and add orderby = 'weight '.

========================================================== ==================================

When using the arclist label, many children's shoes want to sort by the higher the weight, and then move the arclist. lib. Php file to the lower order. The method is as follows:

Open/include/taglib/arclist. lib. php

About 572 rows

The code is as follows: Copy code

$ OrderWeight = list_sort_by ($ orderWeight, 'weight ','Asc');

Change to (red part)

The code is as follows: Copy code

$ OrderWeight = list_sort_by ($ orderWeight, 'weight ','Desc');

OK.

========================================================== ======================================

The complete expression method is as follows:

The code is as follows: Copy code

{Dede: arclist row = 1 titlelen = '80' isweight ='Y'Orderby ='Weight'}

{/Dede: arclist}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.