Create a Page of posts

Maybe sometimes we need to create a page to collect many posts that have same factor, or they are about the same topic. For example, now I have posted several posts about my journey at Yangshuo. Then I wanna create a page to display them. My plan is to create a page called “footprints” that can show a list of all my posts about journey. And then, I wanna create a sub-page to display some of them, focused on the Yangshou journey. Like this:
page&subpages
Then the first step is to create the “footprints” page. There are several ways to do that.

  • The lazy one is to let it done with some plugins, such things related with “list”, anyway, I don’t remember :mrgreen: . That’s quite easy to make it work. So let’s go to the second one.
  • DIY the page by yourself.  When you decide to DIY such page by yourself, we have to make a file called template file which control how the page display.

The way to create a template file:

  1. : Make a copy of your “index.php” in the using theme folder, or the “single.php” if you want the comment feature. And add a few line to mention that this is a template file, just like:
    1
    2
    3
    4
    5
    
      <?php
    /*
    Template Name: yangshuo
    */
    ?>

    Then rename as “tour.php”.

  2. : Modify some codes.
    you can replace the codes which fetching the posts data by new codes that get the post list function.
    Or make it as what I do:
    Find the sentence about fetching all post like:

    1
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    replace with

    1
    2
    
    <?php query_posts("cat=55"); ?>
    <?php while (have_posts()) : the_post(); update_post_caches($posts); ?>

    That is to choose those category belong to “tour” (ID =55).
    Then find and delete the part of post content:

    1
    2
    3
    4
    
                    <div class="content">
    			<?php the_content(); ?>
    			<div class="fixed"></div>
    		</div>

    Then we got a “list” that display the post only with those title and some meta information. Like this

  3. : Add page called “footprints” that using this template and publish~
  4. In fact there is another way to do that, by using the search feature of word press.

    1. : We need a search link that show the post related to tour. Like this: http://www.solesky.com/category/tour-fun/
    2. : Create a template called tour2.php by copying the index.php and add a heading like this:
      1
      2
      3
      4
      5
      6
      
      <?php
      /*
      Template Name: tour
      */
      ?>
      <script>location="http://www.solesky.com/category/tour-fun"</script>
    3. Maybe you are clear now. This time we use the script to make a automatic “jump” to the search page of “tour”. That also make a good list for us. But this time we can’t modify the detail such as the order and meta and so on. Anyway, this methods is easier~

      OK, the “footprints” page show a list of posts about all my tour.
      Then I have to create different feature like Yangshuo tour feature.

      The steps are quite similar. Create a template file called “yangshuo” and do step 1 as when we create the “tour.php” above.

      Now we find the codes

      1
      
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

      And modify it to display only on the topic about Yangshuo.
      This time we use tag selection instead, so we replace this line by:

      1
      2
      
      <?php query_posts('tag=yangshuo&order=ASC'); ?>
             <?php while (have_posts()) : the_post(); update_post_caches($posts); ?>

      That’s to say we only query the posts those have Yangshuo tag from database.

      And I don’t modify the rest part cause I want to display the content.

      Like this

      Then make a sub page called “Yangshuo” belongs to the “footprint” page using this template file and publish~
      ~

Jul 18th, 2009 | Posted in Technique
Tags: , ,
  1. Wow
    Jul 18th, 2009 at 12:25 | #1

    Learning word press. Thx

  2. Jul 21st, 2009 at 10:30 | #2

    you are really my idol~~~~

  3. Jul 21st, 2009 at 20:35 | #3

    @pink
    Faint… This is just some web design tips. Nothing to be surprised. 😐

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).