Show different PHP wordpress layout if there is or there is no featured image

0

How can I do to show an article with a totally different layout for articles that have a prominent image and another layout, for articles that do not have a prominent image?

    
asked by Jhoedram 27.09.2018 в 06:00
source

1 answer

1

You can do something like that inside your template:

single.php

<?php

get_header();

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        if ( has_post_thumbnail() ) {
            get_template_part('views/post-with-featured-image');
        } else {
            get_template_part('views/post-without-featured-image');
        }
    }
}

get_footer();

views / post-with-featured-image.php

<h1><?php the_title(); ?></h1>
<?php the_post_thumbnail('full'); ?>

views / post-without-featured-image.php

<h1><?php the_title(); ?></h1>
    
answered by 27.09.2018 в 06:34