I. general method of adding the previous and next links 1. this method can be seen in almost all Wordpress themes. Generally, add the following code below the document content in the Single. php file. if you do not have this function, you can add it yourself. & Lt ;? Phpprevious_post_link ('previous: % link ')? & Gt; & lt
I. general method of adding the previous and next links
1. this method can be seen in almost all Wordpress themes. Generally, add the following code below the document content in the Single. php file. if you do not have this function, you can add it yourself. As follows:
2. there is a very big problem when adding this article. if it is the first article or the last article, the previous article or the next article will appear blank.
2. add the previous and next links to the blank
1. to solve the above problem, it is natural to add a judgment to output the else. when there is no previous or next article, a sentence is displayed, as shown below:
3. display the previous and next links under the same category
1. to better understand this principle, let's first learn the function format of the previous and next sections of Wordpress:
2. related descriptions:
$ Format: format the displayed string. the default value is "'? % Link. the default value of the second function is "% link ?".
$ Link: the displayed string. the default value is the "$ title" of the previous or next one. you can also set it to another string you want to display.
$ In_same_cat: indicates whether an article of the same category is explicitly displayed or not classified. the default value "false" indicates that an article of the same category is not classified and is determined only by the posting time.
$ Excluded_categories: indicates whether a category is excluded when the previous or next topic is displayed. it is excluded by default. if so, the category ID is listed here and separated by commas.
3. as you can see, to achieve the previous and next links under the same category, you only need to add a judgment on the basis of the above: true, which will be displayed when there are articles under the same category. For example:
4. but there is also a problem here: when the previous and next articles under the same category are specified, the white space will still be displayed, rather than the "already the last article" in the output code ", therefore, we need to specify the ID for a specific category. The code is as follows:
Term_id) ;}$ categoryIDS = implode (",", $ categoryIDS);?>
4. add the previous and next link codes under the same category
1. use add_filter to add. Let's first learn about add_filter:
2. parameters are described as follows:
$ Tag: $ function_to_add name of the filter to be hooked. the default value is none.
$ Function_to_add: name of the function called when the timer is applied. the default value is none.
$ Priority: Weight. when multiple add_filters exist, the priority can be determined here. the default value is 10.
$ Accepted_args: number of documents acceptable to the function. Default value: 1.
3. after completing the preceding steps, go directly to the function, define a function name, and execute the function using add_filter. the advantage here is that when your Wordpress has multiple add_filters, you can use priority to determine the priority relationship. In this way, the previous and next links you add can be followed by the article.
4. add the following code to your Function. php file. As follows:
Function freehao123in (){
Term_id) ;}$ categoryIDS = implode (",", $ categoryIDS);?>
} Add_filter ("the_content", "freehao123in", 2 );