0

I need to rearrange how my comments are displayed depending on the page template.

My posts and standard pages are displayed in in the middle of the screen, and thus need to share the same comment layout. I then have a right sidebar page layout and so I need the comments pages with that template to be aligned to the left of the page. I am attempting to this like so

<?php if( is_single() || is_page()): ?>
<div class="col-lg-12">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
<?php else: ?>
<?php if(is_page_template('right-sidebar.php')) ?>
    <div class="col-lg-12">
        <div class="row">
            <div class="col-lg-7 col-md-12">
<?php endif; ?>

However, my single stadard pages are taking the layout of the html under the second if condition.

What am I misunderstanding about this?

2

Your code will never get to the is_page_template() if statement because is_page_template() can only be true when is_page() is also true.

It also looks like you've got some muddled elseif syntax (I think that's what you want?) and some generally inefficient code that repeats a lot.

I'd do this:

<?php if( is_page_template('right-sidebar.php') ) { // check for page template
    $layout_classes = 'col-lg-7 col-md-12';
} elseif( is_single() || is_page() ) { // it's not the page template. Is it at least a post or page?
    $layout_classes = 'col-lg-8 col-lg-offset-2';
} else { // I suspect you want a fallback condition, not sure what it is.
    $layout_classes = '{something}';
} ?>

<div class="col-lg-12">
    <div class="row">
        <div class="<?php echo $layout_classes; ?>">
1
  • Oh wow, that is a far better way of handling it and it works! Thank you, I've learned something new!
    – user37474
    Aug 28 '14 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy