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:

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
. 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:
- : 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”.
- : 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
- : Add page called “footprints” that using this template and publish~
- : We need a search link that show the post related to tour. Like this: http://www.solesky.com/category/tour-fun/
- : 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>
In fact there is another way to do that, by using the search feature of word press.
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.
Then make a sub page called “Yangshuo” belongs to the “footprint” page using this template file and publish~
~
Learning word press. Thx
you are really my idol~~~~
@pink
Faint… This is just some web design tips. Nothing to be surprised.