Home  >  Article  >  CMS Tutorial  >  How to display all articles on one page in wordpress

How to display all articles on one page in wordpress

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-19 13:51:033093browse

How to display all articles on one page in wordpress

Let WordPress display all categories of articles on one page

1. Copy a page.php file and change it to page -abc.php, and create a new page in the WordPress background, and change the fixed link address to abc (this abc can be optional, but it must correspond to page-abc).

2. Find the following code

<?php the_content(); ?>

in this page-abc.php file and add the following code after the code

<?php
    $cats = get_categories();
    foreach ( $cats as $cat ) {
    query_posts( &#39;showposts=10&cat=&#39; . $cat->cat_ID );
?>
    <h3><?php echo $cat->cat_name; ?></h3>
    <ul class="sitemap-list">
        <?php while ( have_posts() ) { the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php } wp_reset_query(); ?>
    </ul>
<?php } ?>

Remember to save and update page-abc.php document.

At this point, let’s refresh the newly created abc page below to see if articles under all categories have been displayed? The above code displays 10 articles in each category by default. If you need to display all articles, you only need to change the 10 in the code to a value of 1000 or greater.

Related recommendations: "WordPress Tutorial"

Let WordPress display several categories of articles on one page

How many categories does this display? The implementation method of articles in a category is the same as the method of displaying articles in all categories. You only need to change the code

$cats = get_categories();

in step 2 to

$cats = get_categories(array(&#39;include&#39; => &#39;1,2,3&#39;));

, where 1 and 2 ,3 is the category ID you want to display.

The above is the detailed content of How to display all articles on one page in wordpress. 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