Insert the following code into the functions.php
Get policies for related articles: Manually specify > tags > Categories > Random
//related articlesfunctionAdd_related_posts ($content){ return $content.wp_related_posts ();} Add_filter (' The_content ', ' add_related_posts ');//Hookfunctionwp_related_posts () {Global $post; $num= 5;//Number of articles $counter= 1; $exclude _id= Get_post_meta ($post->id, ' related ',true);//get related articles for manual pinning if($exclude _id){ $args=Array( ' Post_status ' = ' publish ', ' Post_type 'Array(' Post '), ' post__in ' =Explode(‘,‘,$exclude _id), ' posts_per_page ' =$num ); $posts= Get_posts ($args); foreach($posts as $SB){ $output. = ' <li><a href= '. Get_permalink ($SB->id). ' > '.$SB->post_title. ' </a></li> ';//Customizable Styles $i++; } } if($i<$num){//after the number of custom articles is insufficient, it is processed by classification and labeling $tagsid=Array(); $catid=Array(); $thisid[] =$post-ID; $posttags=get_the_tags (); $catids=get_the_category (); if(!Empty($posttags)) { foreach($posttags as $tag) { $tagsid[] =$tag-term_id; } } if(!Empty($catids)) { foreach($catids as $cat) { $catid[] =$cat-term_id; } } $args=Array( ' Post_type ' = ' post ', ' post__not_in '$thisid, ' ignore_sticky_posts ' + 1, ' posts_per_page ' = ($num-$i), ' tax_query ' =Array( ' Relation ' = ' or ',//change to and must be in the same category as the label Array( ' Taxonomy ' = ' post_tag ', ' field ' = ' term_id ', ' terms ' =$tagsid, ),Array( ' Taxonomy ' = ' category ', ' field ' = ' term_id ', ' terms ' =$catid, ), ), ); $RSP= Get_posts ($args ); foreach($RSP as $SB){ $output. = ' <li><a href= '. Get_permalink ($SB->id). ' > '.$SB->post_title. ' </a></li> ';//Customizable Styles $i++; } } $final= ' $output. ' </ul> '; return $final;}
If you want to add a custom related article, just create a new custom column, add the article ID, multiple articles in English, separated
If you want to customize the position and adjust the style, the_content
then remove the hooks and then call the wp_related_posts
function manually
Article reference from http://www.2zzt.com/jcandcj/7280.html
WordPress can customize the code to get related articles