我想创建一个 “所有帖子” 页面上的页面 海洋字节博客 其中包含迄今为止帖子所有标题的无序列表,每个标题都超级链接到其博客文章。

似乎有几个插件可以执行类似的操作,但是大多数插件尚未列出WordPress 3.0+,或者他们想按年,然后按月将博客帖子子集。这是不需要的。

对“最佳方式”有任何建议吗?

谢谢。

有帮助吗?

解决方案 3

我最终在包含以下代码的21个主题文件夹中创建了一个名为“ AllPosts-page.php”的页面模板:

<?php
/**
 * Template Name: All Posts
 *
 * A custom page template for displaying all posts.
 *
 * The "Template Name:" bit above allows this to be selectable
 * from a dropdown menu on the edit page screen.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

  <div id="container">
   <div id="content" role="main">
<h2>Archive of All Posts:</h2>
  <ul>
    <?php wp_get_archives('type=postbypost'); ?>
  </ul>


   </div><!-- #content -->
  </div><!-- #container -->

<?php get_footer(); ?>

然后,我使用WordPress管理系统创建了一个新页面,其中包含“所有帖子”的标题,然后从下拉列表中选择“所有帖子”模板。不需要在体内输入任何东西。

可以通过:

www.oceanbytes.org/all-posts/

“ wp_get_archives”的默认值是“每月”,但我选择了“后托管”,因为我只想在长列表中列出所有帖子。通过WordPress网站可以通过 功能参考/wp获取档案

其他提示

创建一个新的模板文件,并将其作为循环进行操作:

query_posts( array( 'posts_per_page' => -1, 'post_status' => 'publish' ) );
if( have_posts() ):
  echo '<ul>';
  while( have_posts() ):
    the_post();
    echo '<li><a href="';
    the_permalink();
    echo '">';
    the_title();
    echo '</a></li>';
  endwhile;
  echo '</ul>';
endif;
wp_reset_query();

然后,只需将该模板用于页面,它将自动生成页面。查看 法典页面 为了 query_posts() 有关如何更改查询的更多信息。

“最佳方式”将使用自定义页面模板。就像 index.php 循环浏览所有帖子,您可以运行自定义查询以循环浏览所有内容,并且只能回应所需的信息(标题,URL)向浏览器。

以下是一些用于构建自定义页面模板的好教程:

许可以下: CC-BY-SA归因
scroll top