wordpress调用博客全部文章列表

发布于 2021-11-24 更新于 2021-12-01 当前分类:» 学习笔记 阅读数:275

创建一个名为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检查



1 条评论

发布评论


Warning: error_log(C:\wwwroot\16km.net\wp-content\plugins\spider-analyser/#log/log-2700.txt): failed to open stream: No such file or directory in C:\wwwroot\16km.net\wp-content\plugins\spider-analyser\spider.class.php on line 2900