2024年4月23日

北京天佑工作室

不亂於心,不困於情,不畏將來,不念過往。

wordpress调用博客全部文章列表

1 min read

创建一个名为page-home.php的新页面模板文件 最好的方法是将index.php中的代码复制并粘贴到新页面中…… 在此页面内创建一个新的模板调用..

<?php
/**
 Template Name: home
 */
?>

在这个页面里粘贴你的index.php代码..

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>
            <?php the_content('<p>Read the rest of this page &raquo;</p>'); ?>
            <?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
            <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
        </div>
        <?php endwhile; endif; ?>

这将像往常一样显示您的主页,然后您必须创建一个新的wordpress数据库调用,以显示您想要的所有类别的最新帖子或显示所有类别的所有帖子。

<?php

//The Query
query_posts('posts_per_page=5&cat=YOUR_CATEGORY_HERE');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
 ..
endwhile; else:
 ..
endif;

//Reset Query
wp_reset_query();    
?>

这将循环显示帖子并显示您的最新帖子.. 通过wordpress查询帖子codex检查

About The Author

1 thought on “wordpress调用博客全部文章列表

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Copyright © All rights reserved. | ICP 2021040747 -1 by 湤 .