0

I have created a split screen template which I want to use accross various pages. I want the content to be different on both sides in all of these templates. How do I pass in different content to each side of these template parts? Or is there another way?

I was considering adding the split screen for each page, but that isn't very DRY. My split screen template HTML is below:

<section id="content">
    <section class="left-split">
        <div class="left-split-content">

            // left side content here

        </div><!-- left split content -->
    </section><!-- left split -->

    <section class="right-split" data-spy="scroll" data-target="#myScrollspy" data-offset="70">
        <div class="right-split-content clearfix">

            // right side content here

        </div><!-- content -->
    </section><!-- right split content -->

</section><!-- content -->

1 Answer 1

0

1. Simply call the template part in each place.

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

and

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

You would then create content-left.php and content-right.php templates.

2. A different approach would be to call do_action there instead. eg.

<?php do_action('template_content_left'); ?>

This could give you an extra level of control over the content template used. eg. in your functions.php you could use something like:

if (is_page('special')) {add_action('template_content_left','template_special_content_left');} 
else {add_action('template_content_left','template_content_left');}  

function template_special_content_left() {get_template_part('special-content','left');}
function template_content_left() {get_template_part('content','left');}

This may suit you better if you need to get the content from different places depending on the current page conditions.

EDIT custom field example, closer to needs described...

if (is_page('about-us')) {
    add_action('template_content_left','template_menu_output');
    add_action('template_content_right','template_content_output');
} 
elseif (is_page('services')) {
    add_action('template_content_left','template_services_field_left');
    add_action('template_content_right','template_services_field_right');
}

function template_menu_output() {echo "CUSTOM MENU";}
function template_content_output() {the_content();}

function template_services_field_Left() {
    global $post; echo get_post_meta($post->ID,'fieldkey1',true);
}
function template_services_field_right() {
    global $post; echo get_post_meta($post->ID,'fieldkey2',true);
}

Just replace with ACF functions for outputting the desired fields.

2
  • Thank you! I think that's close to an answer. But what I mean is for instance on my 'about us' there will be a menu on the left and content on the right. But on my 'services' there will be content on both sides. So how can I change the content which will be added in that space according to which page I am on. I will be using ACF if that makes any difference.
    – JoshRicha
    Commented Feb 8, 2016 at 3:14
  • You probably want to go for using the do_action method then, because you can hook any funciton to that action conditionally, including the output of a custom field.
    – majick
    Commented Feb 8, 2016 at 12:30

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.