1

A few pages share a common template. Each of these pages need different images placed above the main content area. How do I do this?

The images need to appear above the editable region (ie WYSIWYG editor) because the images need to extend all the way from left to right.

Edit:

I am thinking of doing something as below in my template code. I am using a specific template plugin that also allows me to add specific markup along with the images so that I can style the images in different ways. Let me know if the following approach is fine or is there a better way to deal with this without having to hard-code the page ids directly into the template?

if(is_page(10)) {
  echo do_shortcode('[plugin_shortcode 1 .....]');
} else if (is_page(11)) {
  echo do_shortcode('[plugin_shortcode 2 .....]');
} else if (is_page(15)) {
  echo do_shortcode('[plugin_shortcode 3 .....]');
}
  • Template thing is a front-end thing, and WYSIWYG Editor is the back end thing. You failed to inform us about your actual scenario, I'm afraid. Please edit and add more detail so that we can understand your context. – Mayeenul Islam Nov 26 '14 at 15:56
  • Are you asking how to have a page template that's on multiple pages but is using different images/content? If you are, why not use the_post_thumbnail above the_content on your template? If that's not what you meant, as Mayeenul said, you'll need to provide more clarification. codex.wordpress.org/Function_Reference/the_post_thumbnail – RachieVee Nov 26 '14 at 18:48
  • @RachieVee I could use the_post_thumbnail but I need to load multiple images and also need specific markups around the images. Please see my edit above and let me know if there is a better way to resolve this. Thanks. – user1448031 Nov 26 '14 at 21:27
  • 1
    You can also try custom fields - does each page have the same amount of images? Also, is there any reason why you're using a shortcode rather than html and php for the images? Take a look at ACF and see if maybe it can be helpful to you: advancedcustomfields.com/resources/image – RachieVee Nov 26 '14 at 21:48
  • @RachieVee Thanks. ACF plugin has worked quite well for my purpose. – user1448031 Nov 29 '14 at 19:22
1

You could try the loop_start hook depending on what position you want the image and use the code in your functions file.

add_action('loop_start', function() {
if(is_page(10)) {
  echo do_shortcode('[plugin_shortcode 1 .....]');
} else if (is_page(11)) {
  echo do_shortcode('[plugin_shortcode 2 .....]');
} else if (is_page(15)) {
  echo do_shortcode('[plugin_shortcode 3 .....]');
}});

Or you could pull the images from your images folder and wrap each in a unique class.

add_action('loop_start', function() {
if(is_page(10)) {
   echo '<img class="image-one"><img src="' . get_stylesheet_directory_uri() . '/images/one.png" /></img>'; 
} else if (is_page(11)) {
   echo '<img class="image-two"><img src="' . get_stylesheet_directory_uri() . '/images/two.png" /></img>'; 
} else if (is_page(15)) {
   echo '<img class="image-three"><img src="' . get_stylesheet_directory_uri() . '/images/three.png" /></img>'; 
}});

Or hard code the images into your template file.

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.