Single Post View

WordPress has a template function that tells you if the page you are viewing contains a single post: the is_single function. You'll use that template function to decide to exclude the sidebars and allow the post and comments to fill the width of the template. Listing 17-9 show the modified code to make this happen.

Listing 17-9. Testing for a Single Page in index.php

<div id="pagecontent"> <?php if (is_single()) { $main_content_class = 'main-content-full';

else

$main_content_class = 'main-content-norm';

include_once('main-content.php');

include_once('sidebar-a.php'); include_once('sidebar-b.php');

Notice a couple of big changes here. First, all the PHP code is inside one block. You don't need to include each line of PHP inside its own <?php ?> tags. You can amalgamate multiple PHP lines. This works well in this case because there is no longer any HTML code mixed in.

Second, you use the WordPress template function is_single to test if the reader is viewing a single post. If the function returns true, then you set your CSS class variable to main-content-full. If it is not true, the else part of the clause is executed, setting the CSS class variable to the normal main-content-norm. The main-content building block isn't included. Then you test again whether you are viewing a single page. This time the test is negative. The exclamation mark in front of the is_single function negates the test. This test means, "If the page is not a single post, include the two sidebar building blocks." When you are viewing a single page, the main content should be full width and the sidebars will not be output. This results in the view shown in Figure 17-6.

We can split our theme file into multiple parts giving us a set of building blocks from which to construct the layout for any given situation.

Proin pulvinar risus ac orci. Praesent rhoncus luctus tortor. Quisque pulvinar justo sed enim. Maecenas orci. Cras velit dui, ultrices nec, lacinia ut, cursus in, lectus. In eu erat eu velit imperdiet nonummy. Suspendisse accumsan viverra mauris. Curabitur sit amet risus. Aliquam ullamcorper sodales neque.

Proin pulvinar risus ac orci. Praesent rhoncus luctus tortor. Quisque pulvinar justo sed enim. Maecenas orci. Cras velit dui, ultrices nec, lacinia ut, cursus in, lectus. In eu erat eu velit imperdiet nonummy. Suspendisse accumsan viverra mauris. Curabitur sit amet risus.

2 Responses to "Building Block"

August 18th, 2005 at 8:29 pm

I thinks this is a very good idea. In fact... Pellentesque eleifend libero a urna. Curabitur elit sem, eleifend in, pulvinar sed, iaculis vitae, tellus. Donee eget turpis.

Suspendisse potenti. Praesent vel libero a est iaculis porttitor. Donee risus. Sed ut pede. Integer eget magna ut nibh aliquet blandit. Praesent dapibus enim in ipsum. In hac habitasse platea dictumst. Aliquam erat volutpat. Praesent nunc. Etiam eleifend rhoncus mauris. Nam tempor condimentum libero.

2. Danny Says:

August 18th, 2005 at 8:31 pm

I agree, the blah you blather, and blip ... In elit felis, faucibus nec, consectetuer eleifend, molestie a, erat. Nullam fermentum, lorem quis molestie congue, turpis erat sodales lorem, quis luctus dolor mi sit amet sem. Morbi eget ante. Aenean nulla. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc in sem. Etiam feugiat, augue non vehicula semper, purus lacus bibendum metus, tempor ornare tortor diam eu libero.

Leave a Reply

Danny Name (required)

| d an<® ex am p le .co m Mail (will not be published) (required)

Figure 17-6. Single-post view without sidebars

Was this article helpful?

0 0
Six Figure Blog Marketing

Six Figure Blog Marketing

Take Advantage Of This Technology In The World Of WordPress™ Blogging And Start Making Real Residual Money Again. Even If You Are New To The Playing Field, It's Easy To Make Money Again On The Web, With A Free WordPress™ Blog, Some Good Advice And A New

Get My Free Ebook


Post a comment