jwesonga
Member
Posted 2 years ago #
My page template has the following CSS:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="col1">
<img src="images/77189281.jpg"/>
</div>
<div id="col2">
<h1><?php the_title(); ?></h1>
<h2>Mission</h2>
<p>
<?php the_content();?>
</p>
</div>
<?php endwhile; endif; ?>
I'd like to be able to conditionally display the image within col1 only if there's an image in the content/body of that particular page.
Any way to do this using the conditional tags?
jwesonga
Member
Posted 2 years ago #
Figured this out:
Create a functions.php file in the themes folder.
Add the following to the functions.php add_theme_support( 'post-thumbnails' );
And then modified my page.php template to have the following:
<?php
/*
Template name: Page
*/
?>
<?php get_header();?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="col1">
<?php if (has_post_thumbnail()){
echo the_post_thumbnail();
}
?> </div>
<div id="col2">
<h1><?php the_title(); ?></h1>
<p>
<?php the_content();?>
</p>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_footer();?>