Add a second blog page in your existing wordpress site

I guess most of my posts are about wordpress, oh well :).

So, today I wanted to create a second blog page for a site I am building about dog adoptions. Why two blog pages? Well, the first one is about general stories about stray dogs, the second one will be about specific stray dogs that need adoption. I chose to use the “blogish” option for the “adoption” page, as I think it is the best way to present all the dogs, one by one, and also easier for the administrator to add new stray dogs on the list, as well as edit the information about each one. But enough about the background, the subject is how to add this second blog page.

  • First of all, you have to create the categories for your posts. What I mean:

In my case, category 1 (daily stories) are the posts that belong to the 1st blog page, and are about stories concerning stray dogs in the city of Thessaloniki, and not only in Thessaloniki. Category 2 (dogs) are the posts that belong to the 2nd blog page, and are about the stray dogs (each post of category 2 corresponds to a single stray dog…). So, for your two blog pages, you have to separate your posts in the corresponding categories.

  • The second step is to create a new page template. Attention! Don’t mess with the original themes files, always prefer to work with a child them (copy and paste the necessary files that will be changed, inside your child theme folder).
    This is very very easy. Just use your favorite text editor and duplicate the file index.php. Save this new file however you want (I named it dogs.php). In the beginning of this file, just before the “<?php get_header(); ?>” insert this code:

<!--?php /* Template Name: dogs */ ?-->

Of course you will replace “dogs” next to the template name, with the name you want to give to your template (for example cats, cars, space marines…. whatever).

At the end of this step, you have the initial index.php file of your theme and your new file (dogs.php in my case), which is going to be used for your new template.

  • The third step is to tell these two files, to show ONLY one of the two posts categories that you created in the first step. Index.php will be used for the default blog page, dogs.php will be used for the second blog page.

Inside the index.php file find the line:

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

Just before this code insert this line:

<?php query_posts('category_name=daily-stories&showposts=10'); ?>

Replace “daily-stories” in this line with the SLUG of one of your post categories.

Similarly work on the dogs.php file. Find

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

Just before this code insert this line:

<?php query_posts('category_name=dogs&showposts=10'); ?>

Replace “dogs” in this line with the SLUG of the other category of your post categories.
As you might expect “showposts=10” defines the number of the posts displayed.

Save and upload / replace these files in your themes folder.

  • Final step: Create a new page, name it Blog2 or however you want, and choose as template the new template that you created.

If all went well, your initial blog will be displaying ONLY the posts of category 1, and this new page will be displaying ONLY the posts of category 2. This process doesn’t mess at all with the rest of your wordpress site. If you have your initial blog as a home page, it will remain so. If you have a static home page and the initial blog is a sub-page, it will remain so. No worries.

One more thing I noticed while styling the page. This second blog page may look slightly different than the original one. Using a debuger I noticed that there is an extra css class (“singular”) which causes the css changes. So, it will need some custom css to fix the differences (for example different size of h1 tag) :).

UPDATE

Sometimes, the above mentioned method may not work as it should. Especially the

<?php query_posts('category_name=dogs&showposts=10'); ?>

may break the new template that you created. So, instead of this, find inside the code the line

query_posts(blah blah blah something in here depending on the theme you are working);

and add “.’&cat=15′”. This will make the new line

query_posts(blah blah blah something in here depending on the theme you are working.'&cat=15');

Where cat=15 is the id of the category you want to display in the specific templated blog page. The category id can be found if you go inside the dashboard – > posts – > categories and hover over the “edit” link for the specific category. On the bottom left part of your monitor you will see something like ../edit-tags.php?action=edit&taxonomy=category&tag_ID=15&post_type=….

And there is your id inside this line. For you it will be another number.

SECOND UPDATE (YEAH!!)

And here comes the moment that you realize that when you have finally many posts and they need a second page to show (they have exceeded the default 10 posts per page…), the second page shows the same posts as the same page. EXCELLENT!

Fix this issue by using this code

<?php global $query_string;
query_posts($query_string . '&cat=15'); ?>

Change category number with your own and your are jet.