0

Any WP theme editor php gurus out there? So I'm using a theme that allows me to force all pages to full width. I have over 10,000 pages. It also forces my posts to full width too. I'm pretty sure I can edit single.php and force the right sidebar to show up but i'm having difficulty doing so. Any help is greatly appreciated. Here's the contents of my single.php file.

The end result is to have only my posts have right sidebar and not my pages that are already full width.

Thanks in advance!

<?php
/**
 * The Template for displaying all single posts.
 *
 * @package zerif
 */

    get_header();

    $sidebar_layout = apply_filters( 'zerif_sidebar_layout', get_theme_mod( 'zerif_blog_sidebar_layout', 'sidebar-right' ) );
    $wrapper_class  = 'content-left-wrap col-md-9';

if ( 'full-width' === $sidebar_layout ) {
    $wrapper_class = 'content-left-wrap col-md-12';
}
?>
    <div class="clear"></div>
</header> <!-- / END HOME SECTION  -->
<?php
zerif_after_header_trigger();

if ( apply_filters( 'zerif_display_area_filter', true, 'single' ) ) {
    $zerif_change_to_full_width = get_theme_mod( 'zerif_change_to_full_width' );
    ?>
    <div id="content" class="site-content">
        <div class="container">
            <?php
            zerif_before_single_post_trigger();

            if ( $sidebar_layout === 'sidebar-right' && empty( $zerif_change_to_full_width ) || is_singular('post')) {
    zerif_sidebar_trigger();
}
            if(is_singular('post')){
    echo '<div class="content-left-wrap col-md-9">';
}elseif ( ! empty( $zerif_change_to_full_width ) || 'full-width' === $wrapper_class ) {
    echo '<div class="content-left-wrap col-md-12">';
} else {
    echo '<div class="content-left-wrap col-md-9">';
}

            ?>
            <?php zerif_top_single_post_trigger(); ?>
            <div id="primary" class="content-area">
                <main itemscope itemtype="http://schema.org/WebPageElement" itemprop="mainContentOfPage" id="main" class="site-main">
                    <?php
                    while ( have_posts() ) {
                        the_post();
                        get_template_part( 'content', 'single' );
                        zerif_post_nav();
                        /* If comments are open or we have at least one comment, load up the comment template */
                        if ( comments_open() || '0' != get_comments_number() ) {
                            comments_template( '' );
                        }
                    }
                    ?>
                </main><!-- #main -->
            </div><!-- #primary -->
            <?php zerif_bottom_single_post_trigger(); ?>
        </div><!-- .content-left-wrap -->
        <?php
        zerif_after_single_post_trigger();

        if ( $sidebar_layout === 'sidebar-right' && empty( $zerif_change_to_full_width ) ) {
            zerif_sidebar_trigger();
        }
        ?>
    </div><!-- .container -->
    </div>
    <?php
}
get_footer(); ?>
3
  • I'm thinking you might be able to add ` || is_singular('post')` to the 2 conditionals that start with if($sidebar_layout ===... Commented Mar 9, 2020 at 21:06
  • Forgive my lack of php skills but where would I put that? I'm not a developer. Thank you though! Commented Mar 9, 2020 at 21:34
  • Meaning that below the header is the sidebar and then below the sidebar is the full width post. No sidebar on the side of the post. Just above the post. Commented Mar 9, 2020 at 21:54

1 Answer 1

0

I'm not certain this would work without seeing the theme but you could try something like this...

Change...

if ( $sidebar_layout === 'sidebar-left' && empty( $zerif_change_to_full_width ) ) {
    zerif_sidebar_trigger();
}

To this...

if ( $sidebar_layout === 'sidebar-left' && empty( $zerif_change_to_full_width ) || is_singular('post')) {
    zerif_sidebar_trigger();
}

This, in theory, would force the left sidebar on posts because I added || is_singular('post'), which simply means OR is a post.

You could do the same thing for where its checking for the right sidebar.

if ( $sidebar_layout === 'sidebar-right' && empty( $zerif_change_to_full_width ) || is_singular('post')) {
     zerif_sidebar_trigger();
}

Since we changed our conditions around we also need to add in some logic to handle the class that is being used.

Change...

if ( ! empty( $zerif_change_to_full_width ) || 'full-width' === $wrapper_class ) {
    echo '<div class="content-left-wrap col-md-12">';
} else {
    echo '<div class="content-left-wrap col-md-9">';
}

To...

if(is_singular('post')){
    echo '<div class="content-left-wrap col-md-9">';
}elseif ( ! empty( $zerif_change_to_full_width ) || 'full-width' === $wrapper_class ) {
    echo '<div class="content-left-wrap col-md-12">';
} else {
    echo '<div class="content-left-wrap col-md-9">';
}

Update: Here is what your full code would look like with the right sidebar. Noticed I moved || is_singular('post') down to the last if statement.

<?php

/**
 * The Template for displaying all single posts.
 *
 * @package zerif
 */

get_header();

$sidebar_layout = apply_filters('zerif_sidebar_layout', get_theme_mod('zerif_blog_sidebar_layout', 'sidebar-right'));
$wrapper_class  = 'content-left-wrap col-md-9';

if ('full-width' === $sidebar_layout) {
    $wrapper_class = 'content-left-wrap col-md-12';
}

?>
<div class="clear"></div>

</header> <!-- / END HOME SECTION  -->

<?php

zerif_after_header_trigger();

if (apply_filters('zerif_display_area_filter', true, 'single')) {
    $zerif_change_to_full_width = get_theme_mod('zerif_change_to_full_width');
?>

<div id="content" class="site-content">
        <div class="container">
            <?php
    zerif_before_single_post_trigger();

    if ($sidebar_layout === 'sidebar-right' && empty($zerif_change_to_full_width)) {
        zerif_sidebar_trigger();
    }
    if (is_singular('post')) {
        echo '<div class="content-left-wrap col-md-9">';
    } elseif (!empty($zerif_change_to_full_width) || 'full-width' === $wrapper_class) {
        echo '<div class="content-left-wrap col-md-12">';
    } else {
        echo '<div class="content-left-wrap col-md-9">';
    }

    ?>
    <?php
        zerif_top_single_post_trigger();
    ?>
        <div id="primary" class="content-area">
                <main itemscope itemtype="http://schema.org/WebPageElement" itemprop="mainContentOfPage" id="main" class="site-main">
    <?php
        while (have_posts()) {
            the_post();
            get_template_part('content', 'single');
            zerif_post_nav();
            /* If comments are open or we have at least one comment, load up the comment template */
            if (comments_open() || '0' != get_comments_number()) {
                comments_template('');
            }
        }
    ?>
            </main><!-- #main -->
            </div><!-- #primary -->
    <?php
        zerif_bottom_single_post_trigger();
    ?>
    </div><!-- .content-left-wrap -->
    <?php
        zerif_after_single_post_trigger();

        if ($sidebar_layout === 'sidebar-right' && empty($zerif_change_to_full_width) || is_singular('post')) {
            zerif_sidebar_trigger();
        }
    ?>
</div><!-- .container -->
    </div>
    <?php
}
get_footer();
?>
7
  • What that did was put the sidebar up on top of the page and below the page is the full width post. Commented Mar 9, 2020 at 21:53
  • I think you need to adjust the class that is being given to the content area, I added some more to my answer. If this doesn't work inspect the page and see what classes are being added to the div after .container Commented Mar 9, 2020 at 22:54
  • That worked brilliantly!!! My only question now is how to get that sidebar to the right because right now it's on the left. I can't tell you how thankful I am that you did this. Commented Mar 10, 2020 at 0:31
  • Glad it helped. Instead of changing the $sidebar_layout === 'sidebar-left' chunk of code leave it how it was and add the new condition to the $sidebar_layout === 'sidebar-right' block of code, the same way you did before. I have the example in my answer Commented Mar 10, 2020 at 1:13
  • Not exactly sure what your mean there. Her's my code. It won't let me put the code here so I edited the original code to show what it is now. Commented Mar 10, 2020 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.