mercredi 18 mars 2020

If else specific category post wordpress

i'm trying to make an if else script but cant get it right. i want a post with the thumbnail left and text right and when i make an other post in the category i want the thumbnail right and text left.

this is my code so far:

<div class="row">

        <?php if (query_posts('category_name=news'))
            if (have_posts()) : while (have_posts()) : the_post(); ?>
                <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
                    <?php
                    if ($wp_query->current_post % 2) {
                        echo "<div class='image-test'>";
                        the_post_thumbnail('thumbnail');
                        echo "</div>";
                        echo "<div class='tekst-rechts'>";
                        the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
                        the_content();
                        echo "</div>";
                    }
                    ?>
                </div>

            <?php endwhile; ?>

        <?php else : ?>

            <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
                <?php
                //echo "Current item is ". (($wp_query->current_post % 2) ? "oneven" : "even");
                //the_title( '<h1 class="entry-title">', '</h1>' );
                the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
                the_post_thumbnail('');
                the_content();
                ?>
            </div>

        <?php endif; ?>

        <?php wp_reset_query(); // reset the query 
        ?>
    </div>

Aucun commentaire:

Enregistrer un commentaire