|

Put the Categories, Archives and All Posts into Pages

I prefer putting pages that contains all the categories, archives and even all the posts in one page to putting these links in the side bar. Actually, most of time it needn’t to stay on every pages. And if it is in the side bar, the search engine will see these links in every page and think it is very important while it is not so important. So the better way is put them in one or several pages.

But unfortunately, WordPress doesn’t provide a simple way to put several pages and put some part like the widget into it. So I write some php script that will call WordPress’s API to put them input pages.

The page template is like this. This template enable the theme and load the common files that contains WordPress’s API functions. Then it generate the header, sidebar and the footer. What we need to do is add the content to replace “TODO: content here” now.

<?php
/**
* Loads the WordPress environment and template.
*/
define('WP_USE_THEMES', true);
if ( !isset($wp_did_header) ) {
  $wp_did_header = true;
  require_once( dirname(__FILE__) . '/../wp-load.php' );
}
?>

<?php get_header(); ?>
<div id="container">
  TODO: Content here.
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

1. Categories

The code for categories is:

<div>
<h1><?php _e('Categories', 'default'); ?></h1>
<div>
<ul>
  <?php wp_list_categories('title_li=&show_count=1'); ?>
</ul>
</div>
</div>

wp_list_categories() can list all the categories as a list. “show_count=1” means the post number under each category will be shown after the category.

2. Archives

The code is:

<div>
<h1><?php _e('Archives by Month', 'default'); ?></h1>
<div>
<ul>
  <?php wp_get_archives('type=monthly&show_post_count=1'); ?>
</ul>
</div>
</div>

wp_get_archives() will show the archives. the type can be changed to weekly, daily to show archives by week or day.

3. All posts

The code:

<div>
<h1><?php _e('All posts', 'default'); ?></h1>
<div>
<ul>
<?php
  //The Query
  query_posts('posts_per_page=1000');
  //The Loop
  if ( have_posts() )
  {
    while ( have_posts() )
    {
      the_post();
?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></li>
<?php
_e('</li>');
    }
  }
  //Reset Query
  wp_reset_query();
?>
</ul>
</div>
</div>

At most 1000 posts’ titles will be listed.

Put these php files into the site, edit the theme files and then enjoy it! :)

Similar Posts

  • Java Calling Native Functions in .DLL on Windows

    How to call a function in .dll from Java on Windows is introduced in this post with an example. Platforms used: OS: Microsoft Windows XP [5.1.2600] C to .dll compiler: MS Visual Studio 2008 JDK: java -version java version “1.6.0_05” Java(TM) SE Runtime Environment (build 1.6.0_05-b13) Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)…

  • | |

    Linux Kernel: fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek

    This change “fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek” (commit 06222e4) in Linux kernel is authored by Josef Bacik <josef [at] redhat.com> on Mon Jul 18 13:21:38 2011 -0400. Description of “fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek” The change “fs: handle SEEK_HOLE/SEEK_DATA properly in…

  • Micosoft招聘部分算法题

    Micosoft招聘部分算法题 1.链表和数组的区别在哪里? 2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法? 4.请编写能直接实现strstr()函数功能的代码。 5.编写反转字符串的程序,要求优化速度、优化空间。 6.在链表里如何发现循环链接? 7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。 8.写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?) 9.给出一个函数来输出一个字符串的所有排列。 10.请编写实现malloc()内存分配函数功能一样的代码。 11.给出一个函数来复制两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠。 12.怎样编写一个程序,把一个有序整数数组放到二叉树中? 13.怎样从顶部开始逐层打印二叉树结点数据?请编程。 14.怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)? 来源:·日月光华 bbs.fudan.edu.cn Read more: Java与C++在语言方面上的不同 4 Ways of Converting String to Int in C++ x86-64 ISA / Assembly Programming References How to Measure Time Accurately in Programs How to Get Available Filesystem Space on Linux: a C Function with a…

Leave a Reply

Your email address will not be published. Required fields are marked *