WordPress is a great blog engine, better, it is even a full CMS. The proof ? It propels the vast majority of self-hosted blogs (well in front of drupal, joomla etc) and is behind hundreds of sites: blogs, information sites, shop windows, ecommerces …

However, like any tool, WordPress has its limitations: it does not allow to have more than one blog page (include page that lists articles or posts). This limitation is inherent in the original architecture of WordPress, which is basically a simple blog engine. But as we said, our dear WordPress is today a real CMS and its different uses require flexibility. Here are four ways to display multiple article pages.

From the most to the most successful, these different techniques have their peculiarities. Three of them are clearly differentiated by their approach to the database, the first one, which is the easiest to set up, does not even have to be put in the sludge (perhaps at the expense of d flexibility).

Using Categories as Blog Pages

This technique is incredibly simple but extremely effective. This is the only way to achieve the desired effect without affecting the code.

Let us summarize the situation. You have a blog and you write articles in different categories. You want for example to have a page with your technical articles on programming, and another with the articles that deal with the news.

Otherwise, you have an e-commerce and you have several product lines. Each product corresponds to a post and you want a page to group the 2-stroke mowers while another one only displays 4-stroke mowers (yes lawn mowers change computers for example!).

From the WordPress menu, simply go to apparence > menus, and then add to your menu the 2-beat category, and the 4-beat category (if your theme supports it).

All you have to do is tick the corresponding categories in your articles so that they “automatically” rank on the right page!

The limit of this technique is that your main blog page always displays all of your articles. You can put a static page on the home page (it’s done in settings> read) and do not assign a specific page to your blog page that contains all the articles. Virtually, it will be non-existent.

This solution is perfectly suited for a company that presents its philosophy, its expertise or its field of activity in homepage for example. But there are many cases where the home page should be the page that lists the articles: imagine an online magazine or the home page does not gather the latest articles published?! In these cases, you will have to open your code editor!

Two or more pages of custom blogs

It is a technique that I use quite often. You only have one administrative interface, one database, and you do not add a table. You will create one or more categories and say in a way to WordPress that for these categories you want it to display them on a page other than that of “normal” blog. Let’s start!

Filter categories on the homepage

Since some categories will be displayed on a separate page, it would not hurt that they also do not appear on the “normal” blog page, right? To do this, it will be necessary to add a small piece of code on the page index.phpof your theme.

No eagerness though! It will be necessary to create the categories in question … Create your categories then, go take a look in your database to retrieve the ID corresponding to these categories. They are stored in the table wp_terms. If you access it by PhpMyAdmin, a little shot of ctrlcmdfor mac) + fwill give you a good hand to find the desired category. For example, if I search for the category What’s Up on Da Web, its slug is whats-up-on-da-weband its ID 6 (it’s only my home).

This time you can open your … index.php. That’s right, you listen to me! So add the following line – before the start of the loop, that is if(have_posts()) :– so that this category no longer appears on the page:

<? php query_posts ( $ query_string . '& cat = -6' ); ?>

In case you want to exclude several categories – let’s say the category with ID 8 in addition to the 6 – put a comma then -8. Like this friends:

<? php query_posts ( $ query_string . '& cat = -6, -8' ); ?>

You understand? Well, let’s pursue!

Let’s create a page template

As things stand, your blog page “index” no longer displays the items whose IDs you have selected. You will now need to create a template for your new blog page.

So create a file, for example live.php, and copy all the contents index.phpof your theme file . Warning, when I say all the index.php, I speak of index.php before modification, ie without query_posts($query_string . '&cat=-6');.

Indeed, this line means “does not display the article (s) I give you the id of the category (in this case 6)”, but it is precisely on this page that one will want view these items, so think about clearing this line! It is also necessary to add a tag at the top of the php file so that wordpress understands that it is indeed a template. Add this tag to the beginning of the file:

<? php / * Template Name: Live * / ?>

Save this file and place it in your theme directory. Now navigate to your administrative interface, create a new page, and then in the attribute panel of the page, choose the template template you just created.

Note: it all depends on how your theme is done. As far as I’m concerned, I had a case management where the loop can not find content. That is to say that before the:

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

I had a condition that came to check that there are many posts to display:

<? php if ( have_posts ()) : ?>

And after closing my loop, which corresponds to:

<? php endwhile ; ?>

I had my condition that came to display an error message plus the search form (only in case there is no item to display), like this:

<? php else : ?> <h2> Oooopppsss ... </ h2> <p> Sorry, but you're looking for something that is not here. </ p> <? php include ( TEMPLATEPATH . "/searchform.php" ); ?> <? php endif ; ?>  


All this little world caused mistakes. So I ve turned the line of the as if have postswell as the elsefollowing to the end of the loop (this corresponds to the second and last of the four blocks of code above).

Note: Removing this error handling has no impact since we arrive at this page in general because of a bad url or a search that does not correspond to any content. In any case, the index.phptheme will take care of it (so do not do the dump to remove it from your index.php, it’s just for your new page we agree).

Let the magic happen

If you go to the new page created ( live.php), you have all the items, even those now missing from your home. It’s all right.

On the other hand, if you have a blank page or an error, you may have an old version of WordPress. In this case, I strongly advise you to make an update (for obvious security considerations). However, in older versions, to be able to launch the loop of another page than the “normal” blog page, you must add these two lines at the beginning of your live.php:

<? php
define ( 'WP_USE_THEMES' , false ); require ( './wp-load.php' ); ?> 

It should work now!

Anyway, having absolutely all of our articles on this page is really not the desired result. So we’ll tell wordpress to show only the articles of a given category on this page. To do this, you must add another piece of code, which you will place just before the line of the while(have_posts()) :, in the following way:

<? php
$ paged = ( get_query_var ( 'paged' )) ? get_query_var ( 'paged' ) : 1 ; 
query_posts ( "category_name = whats-up-on-da-web & paged = $ paged" ); ?>    

// the next line, you already have it, so do not put it twice, 
// just place the above piece before the following line
<? php while ( have_posts ()) : the_post (); ?>

Note that you must place in this piece of code the slug of your category, here whats-up-on-da-web.

Two databases

In my view, the two techniques are less flexible. They work perfectly and will certainly be adapted to specific situations but seem to me a little less clean in their logic.

Nevertheless, the logic applied to these two approaches is often used to offer a blog space to online shops. Quite often e-commerce is based on the specialized CMS Prestashop (there is also Magento or Oscommerce quite popular), but these CMS are just bad enough in the management of editorial content. They excel at editing product sheets, are full of functionality to analyze sales data but are not able to write blog posts or even editorial pages with a lot of content.

So to cheat, a WordPress is often set up with the same graphic as the e-commerce site, we put the right links in the menu of the one and the other and voila!

It is a little the method to the wanéguen! But it is perfectly functional and offers the advantage (or disadvantage) of totally separating the databases from each of your blog pages. In reality, you will have two distinct blogs, two administration interfaces (advantage or disadvantage once again, depending on the use), but from a cosmetic point of view, your visitors will believe that you only have one blog! However, if you prefer to have only one base and one administration interface, go directly to the third approach. Well, let’s attack!

Configure the blog

Let’s say you already have a blog under wordpress on your hosting, at www.myblog.com. You want to add a “life” blog page, to tell your life (help!). To do this, add a directory to the folder containing your wordpress site (next to wp-adminwp-contentetc.). Then copy all the files and folders from your existing wordpress.

wordpress web hosting
wordpress web hosting

Once the copy is complete, delete the file wp-config(/! \ The one contained in life, not the one of your normal blog !!). You can also delete the files contained in /wp-content/uploads. Once done, access this new blog (it is available at www.myblog.com/life). WordPress will ask you to configure it as a new blog (but it’s a new blog!). Provide him with all the information he needs at the database level.

Adapt the template

Once the installation is complete, apply the same theme to your new blog as your main blog. Aside from the content, the two are now identical. It would nevertheless be nice to have a tab in the navigation menu to be able to navigate directly between your two blogs, and give the illusion that it is a single blog. It will need to modify your theme a bit to configure the menu.

Before you immerse yourself in the code, if your theme supports it, you can do this directly from the admin interface. So go to appearance> menus, and then click the link tab. You can now add a menu item to point it to the link of your choice (in this case the address of your second blog).

If, by misfortune, your theme does not support this feature, you are going to have to roll up your sleeves. In case you do not have a menu, it will be enough to write it in the header of your theme:

<ul> <li> <a href = "http://www.myblog.com"> Blog </a> </ li> <li> <a href = "/life"> Life </a> </ li> </ ul>

“Blog” being here your home blog page and “life” brings to your “second blog” now integrated as if the two were making one more. However, it is unlikely that you do not have a menu, since you must have created at least one page to introduce yourself and explain your blog etc. It will be necessary to add this new category to the dynamic menu of wordpress. The adaptation will depend here on the theme you have on your blog. I will be based on twentyten but this manipulation also applies to twentyseven, and should suit most themes.

The wordpress function to automatically generate the menu corresponds to this line in the header file of the twentyten theme:

<? php wp_nav_menu ( array ( 'container_class' => 'menu-header' , 'theme_location' => 'primary' ) ); ?>

It generates the following html code:

<div class = "menu" > <ul> <li class = "current_page_item" > <a href = title = "http://www.myblog.com/" "Home"> Home </a> </ li> <li class = "page_item page-item-643" > <a href = "http://wesharethis.com/live/"> Live </a> </ li> <li class = "page-item page_item -23 " > <a href = "http://wesharethis.com/about">About </a> </ li> <li class = "page_item page-item-91"         > <a href = "http://buzut.fr/contact/"> Contact </a> </ li> </ ul> </ div>

One might just want to add a link before the function wp_nav_menu, however, it generates a list itself (ul), you would get either a link out of the list or two lists against each other, so it would not be a clean solution. We will therefore have recourse to the function wp_list_pages. We will replace the line wp_nav_menu, by this:

<div class = "menu" > <ul> <li> <a href = "http://www.myblog.com"> Blog </a> </ li> <li> <a href = "http : //www.myblog.com/life " > Life </a> </ li> <? php wp_list_pages ( 'title_li = & depth = 1 & link_before = <span> & link_after = </ span>' ); ?> </ ul> </ div> 

So we added several things:

  • First, a div with the menu class. Indeed, the function wp_nav_menugenerates this code, as we saw above, but wp_list_pagesdoes not do so. We add it so that the style defined in the CSS for the menu applies correctly,
  • Then we opened a list to put all our items,
  • The menu items we want to place are our hard links, which lead for one to the home page and the other to the blog page (which is actually another site, but that no one can know now!)
  • Finally, we have placed the function wp_list_pagesthat will dynamically generate links for other pages.

Note: You will find all information about the wp_nav_menu and wp_list_pages functions in the wordpress codex.

Do not forget to update the theme on the “two blogs” so that the whole is coherent. Finally, last little adaptation, in the theme of “life”, modify the link of the logo so that it points to www.myblog.com and not www.myblog.com/live, otherwise it is a little weird !

Last point, as the two blogs do not share the same database, if in your sidebar you have links to categories etc, they will be different on each of your blog pages. Again, some will find that it is an advantage (content that adapts according to the page and the subject), others will not find their account …

A single base but with different tables

That’s going to be very quick to explain. The interest here is that if you do not have another database at your disposal, you can quite configure several blogs with a single database. The technique is exactly the same as the previous one. At the time of the wordpress configuration, when it requests the name of your BDD, the password etc, you give the same information as with your blog already in operation (you will find them if necessary in the file wp-admin), but you change the prefix tables! It’s as simple as that. Roll youth!

Note: I still advise you to make a backup of your database before carrying out this kind of operations, one is never too careful …

Here ! We have finished charging WordPress to fit our needs. It was cool is not it ?! Let me know what you think of this little tutorial. Or simply say thank you, it will be nice, I put a moment to write it -_- ‘!


With a natural and eclectic curiosity, internet surfer, I am interested in everything related to digital: from programming to entrepreneurship, via webmarketing and social networks.

Pin It