WP Post Query with variable item column size

Post loop
<?php

$args = array(
    'posts_per_page' => 10,
    'post_type' => 'post',
);

$query = new WP_Query( $args );

?>

<?php if( $query->have_posts() ) : ?>
<div class='post_wrapper row'>
    <?php $count = 1;?>
    <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    <?php 
        
        if($count===1){
            $col_class ='col-12';
         }else{
            $col_class ='col-6';
         }?>

    <div class="<?php echo $col_class?>">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>

    <?php $count++;?>
    <?php endwhile; ?>
</div>
<?php endif; ?>

<?php wp_reset_query(); ?>
Previous Code

File manager for any website

You can install a File manager for any website you ...

Next Code

HTML img tag to HTML SVG tag [WordPress]

Image to SVG for WordPress. Generate svg code from ...

Leave a Reply

Your email address will not be published.

3 + 17 =

    skype

    Need Coding Help?

    Connect Skype

    ACF

    JavaScript

    jQuery

    Others

    PHP

    WooCommerce

    WordPress

    WooCommerce Mostly used Shortcode

    Most use shortcode for popular eCommerce plugin Wo ...

    Most View or Popular Post on WordPress

    WordPress Post query by user views without plugin ...

    Change WordPress URL in Database with phpMyAdmin and SQL query

    Replace WordPress old URL to new URL with SQL Quer ...

    WordPress Ajax Search without plugin [ Easy ]

    WordPress Ajax Search without plugin. Fully custom ...

    HTML img tag to HTML SVG tag [WordPress]

    Image to SVG for WordPress. Generate svg code from ...

    top