Ready to get started?Download WordPress


Multiple template pages (index single etc) vs is_single statements (3 posts)

  1. mat8iou
    Posted 8 years ago #

    Not so much a problem as a question.
    I've noticed that it is possible to either create separate template pages such as page.php, single.php, or you can combine many of these functions in a single index.php page using statements like is_page or is_single to specify differences where necessary.

    Now, I only discovered this by acident while fiddling around with the code & seeing how something had been done in a different theme, but I was wondering if there was any consensus as to which was the better approach to ake, or what limitations I might not have noticed.

    The advantage of combining the page is that if there are a lot of similarities & you want to modify the theme then you only need to update things once. The most obvious dis-advantage is that the index.html page ends up more complex than it would have been otherwise.

    I am hoping that now when I want to update aspects of my theme that are common to a lot of pages, such as the meta data above & below the posts, then it will be a lot quicker than it was previously, where I copied & pasted between various files (& there is always a chance when doing this that you accidentally overwrite some slight difference that was supposed to be in the statements before.)

    Does anyone else have any thoughts or opinions on how they treat this issue?

  2. Kafkaesqui

    Posted 8 years ago #

    Certainly multiple templates provides a more obvious structure for when and where an element will appear on ones blog, and once you get it there's not a lot to explain. Conditional tags allow you to keep everything in one place (or at least fewer ones), but even those of us experienced in PHP can get lost in the mishmash of if/else statements when using them.

    Personally I use a mix of the two. My archive and category pages are nearly identical, so I use a bit of PHP for those few elements which differ between them. In the case where the conditional code starts looking spaghetti-like I may break things off to separate templates to simplify. Each approach has its good and bad points, and which is best for you depends on how you need to manage your templates. I'm not sure it's something a consensus would help you figure out, though.

  3. mat8iou
    Posted 8 years ago #

    I wasn't looking for a consensus as such (I worded my original message badly in this regard). I was more interested to know if there were any hidden problems or benefits specific to either approach that I hadn't fully appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic