|

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

  • |

    Directly SSH to Hosts’ Internal IPs Through the Gateway

    We have many hosts with internal/LAN IPs like 10.0.3.* behind a gateway and the hosts with LAN IPs can connect to the Internet through the gateway. We used iptables to forward port from the gateway to internal IPs so that users from hosts with Internet connections can SSH to the gateway’s forwarded port to log…

  • MFC程序使用系统风格界面

    VC6默认编译出来的程序在XP下Luma风格下运行也是Windows的经典界面, 有损界面的美观与统一. VC2008默认设置下如果不是使用的unicode也是如此. 本文给出使VC6和VC2008可以编译出使用系统界面风格的解决方案. 1. 使VC6编译出使用系统风格的程序 步骤如下: 1) 创建一个.manifest文件的资源. 在res/文件夹下创建一个跟以程序名加.manifest的文件, 如果程序为test.exe, 则创建test.exe.manifest 文件可由此下载: https://www.systutorials.com/t/g/programming/resultcollector.manifest/ 注意要使用utf-8编码保存。 2) 将新定义的资源加入到.rc2文件中, 类型设为24. 打开res/文件夹下的.rc2文件, 在其中加入如下定义: 1 24 MOVEABLE PURE “res/test.exe.manifest” 其中的文件地址按1)步中修改的设置即可. 之后编译即可, 为了使程序界面可能充分利用系统的界面特性, 可以将界面字体设置为TrueType类型的, 利用Windows XP等系统的屏幕字体平滑特性. 2. 使VC2008编译出使用系统风格的程序 在VC2008下就比较简单了, 如果程序字符集使用unicode则默认就是使用系统界面风格的, 如果选择其它的类型, 则编辑下stdafx.h即可. 最后面部分找到这么一段: #ifdef _UNICODE #if defined _M_IX86 #pragma comment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ processorArchitecture=’x86′ publicKeyToken=’6595b64144ccf1df’ language=’*'””) #elif defined _M_IA64 #pragma comment(linker,”/manifestdependency:”type=’win32’…

  • |

    Vim + cgdb

    I begin to use vim for programming. I like the tools that focus on one function. I used to use emacs. But I think I like vim more. For debugging, I use gdb. But I use the front end cgdb. I can see the codes with the cursor when debugging. I can use F8 for…

  • Make Better Decisions for Your Businesses with Data Visualization

    In today’s time, data visualization has become a significant part of the success story of an organization. With the help of right techniques, visualizing data can reveal insights which the management staff can use in their decision-making in order to make sound data-driven decisions. Mapping software is among the robust data visualization tools that you…

Leave a Reply

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