-2

I'm sure this must be super simple, but Google isn't helping me!

I am using an up-to-date WordPress and I have a two-column layout on my blog section (content left, Twitter feed right) that I am very happy with. This was created using just the Appearance > Widgets page.

Now I want to use the exact same layout for all my pages, which are currently single column.

How do I do this? Do I need to use PHP?

If I open the editor for a page and choose "Blog" as my template, then the whole page is replaced with my blog.

  • that's not a WordPress thing, it's a css stuff – jepser Feb 18 '16 at 4:17
1

1. Add .php in wp-content/themes/

Write

<?php
/**
 * Template Name: <subpage-name>, left sidebar
 * Description: A one-colum template with left sidebar for <subpage-name> ONLY
 */
get_header(); ?>

2. Copy full-width page basic codes.

3. Add new div for

<div id="main" class="<subpage-name>-right clearfix" role="main">

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

                <?php get_template_part( 'content', 'page' ); ?>

                <?php comments_template( '', true ); ?>

                <?php endwhile; // end of the loop. ?>

            </div>
        <div id="main" class="<subpage-name>-left clearfix">
</div>

4. Set style in css.

div#main.<subpage-name>-left{width:240px;float:left;}
div#main.<subpage-name>-right{width:780px;float:right;}
article{margin-top: -44px;}
  • Thanks! Though I want to make this the default template for ALL my pages, will this work? – Richard Feb 17 '16 at 19:23
  • No problem with that but its good to create own page template – Vasim Shaikh Feb 17 '16 at 19:25
  • If you get an answer please mark it solved. – Vasim Shaikh Feb 17 '16 at 19:25
  • 1
    Thanks, I will, but not just yet, because surely there must be an easier and cleaner way than this! – Richard Feb 17 '16 at 23:19
1

There's really two ways to accomplish this. You could create a template (that you'd have to select for each page), or you could replace page.php. Since the theme isn't written by you, you should be using a child theme so that you can still receive updates for your theme from the creator. It's good practice to keep your code separate from code that is a part of a theme, so whether you make your own template, or create a new page.php, you should be using a child theme.

If you don't know PHP, it might sound daunting, but it's not too bad if you are familiar with HTML/CSS.

Any files that exist in the child theme will be used in place of the file from the parent theme. So you will have to make a new directory under wp-content/themes with a style.css and functions.php as described here.

Once you have your child theme setup, you can just create a new page.php that has the structure/HTML from your two-column layout template, but uses the WordPress functions to show the content itself. (Also, make sure you copy the get_header(); and get_footer(); bits to your new file - they do exactly what they sound like they do.)

So your main/left section would contain this (or something like it):

<?php
// Start the loop.
while ( have_posts() ) : the_post();

    // Include the page content template.
    get_template_part( 'content', 'page' );

    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || get_comments_number() ) :
        comments_template();
    endif;

// End the loop.
endwhile;
?>

Your right/sidebar section would contain this (or something like it):

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    <div id="widget-area" class="widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </div><!-- .widget-area -->
<?php endif; ?>

(This is how it gets the information that you put in the Appearance > Widgets page.)

--

With all that being said, if you are comfortable with HTML and CSS, this shouldn't be too hard to accomplish. I'm not sure what your experience is, so I don't want to assume anything. There really isn't an "easier" way to do this, because you are creating a brand new template. Your theme's "Blog" template will always retrieve blog posts, because that's how they set it up. If you aren't comfortable working in PHP files, you could suggest to the theme author that they add a two-column template you could use.

Best of luck!

Reference: https://codex.wordpress.org/Child_Themes#Template_Files

Your Answer

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

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