Home  >  Article  >  Backend Development  >  Use php to implement the function of sticking articles to the top

Use php to implement the function of sticking articles to the top

不言
不言Original
2018-06-12 17:49:413178browse

This article mainly introduces the method of php to implement the article top function, and analyzes the operation steps and related implementation techniques of php top function in the form of examples. Friends in need can refer to the following

The examples in this article describe php How to achieve the function of pinning articles to the top. Share it with everyone for your reference, the details are as follows:

Yesterday, the customer asked me to pin the article to the top. I haven't done it before. I did it with the guidance of my colleagues. It was a very simple thing at first, but it took me a long time to do it. I really lack understanding of the program. Let’s write a blog to record it.

The first step is to create two fields in the article table for the pin function. One is the top field, timestamp type, "Definition" is selected by default, and is used to store the time of the pin operation; there is also a flag field, int type, used to determine whether to pin the item to the top. The pin is 1, otherwise it is 0. .

The second step is to modify the template page. Add a top column to the list option, and write the following code in the corresponding line below: 0f5c395f522888a18b7460433a3c47a2 {{if $logs[data].flag}} 5d5a53854f5001828e2783b90443bca7Cancel top5db79b134e9f6b82c0b36e0489ee08ed{{else}} cc9e409e948607327b919b31b262cc31Top5db79b134e9f6b82c0b36e0489ee08ed{{/if}}b90dd5946f0946207856a8a37f441edf

Just use the flag to determine whether it is pinned.

The pinned js corresponding to the page:

function istop(id,flag){
$.ajax({
type: "POST",
url: "?m={{'article'|encrypt}}&a=savePost",
data: "id="+id+"&flag="+flag,
dataType:"json",
success: function(msg){
if(msg.status == "true")
{
 window.location= '?m={{'article'|encrypt}}';
}
else
{
 alert(msg.message);
}
}
});
}

The third step is to make slight modifications in the program. First sort by whether to stick to the top, then sort by the stick time, and then sort by the default.

$sql .=" ORDER BY flag DESC,top DESC,id DESC ";

(Remember the fields we added?)

This completes the function of pinning the article to the top.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Usage of remainder and remainder in PHP

How to generate promotion posters in PHP

Use PHP to implement the function of packaging zip and downloading

The above is the detailed content of Use php to implement the function of sticking articles to the top. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn