Home >CMS Tutorial >WordPress >How to control the categories displayed on the homepage in WordPress

How to control the categories displayed on the homepage in WordPress

藏色散人
藏色散人forward
2021-01-14 17:17:353846browse

The following column WordPress Tutorial will introduce to you how to control the categories displayed on the homepage in WordPress. I hope it will be helpful to friends in need!

How to control the categories displayed on the homepage in WordPress

wordpressControl the categories displayed on the homepage

WordPress will display the latest articles on the homepage, you can Control the number of articles displayed in the background, but cannot control the categories to be displayed. General CMS systems can control the categories to be displayed, but sorry, WordPress is not a CMS. However, WordPress can also control the categories to be displayed. Although it cannot be set in the background, it can be achieved by modifying the template code.

One method is:

<?php if (is_home()) {
query_posts("cat=-1,-2,-3");//表示在首页排除 分类ID为 1 2 3的文章
}
?>

Put this code in the front part of the index.php file in the theme directory. (Before controlling the code to display the article)

Another method:

9a343a062293fbbc0f310e4e31fd09b3

Then add the above code after this sentence. In comparison, the first method is more convenient, and the second method also provides a solution.

The above is the detailed content of How to control the categories displayed on the homepage in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete