Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Wordpress even odd post count

<?php
    $count = 0;
    if (have_posts()): while (have_posts()) : the_post();
        if ( ++$count == $wp_query->post_count && ( $wp_query->post_count % 2 ) == 1 ) {
            // if final count is reached AND final count is odd
            // full width item
            $postclass = "fullwidth";
            $opentag = '';
            $closingtag = '</div>';
        } else if ( ( $count % 2 ) == 1 ) {
            // if $count is odd it is the first item in a 'row'
            $postclass = "halfwidth first";
            $opentag = '<div class="home-ci-row">';
            $closingtag = '';
        } else {
            // second item in a row
            $postclass = "halfwidth second";
            $opentag = '';
            $closingtag = '</div>';
        }
?>
    <?php echo $opentag; ?>
    <div class="main-column-item-wrap <?php echo $postclass; ?>">
    CONTENT OF POST : Title, Thumbnail, Excerpt... etc
    </div><!-- main-column-item-wrap -->
    <?php echo $closingtag; ?>

<?php endwhile; endif; ?>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel gigapay delete payout 
Php :: Wampserver does not use, modify or require the PATH environment variable. 
Php :: PHP Parse error: Unexpected character "" (ASCII 22) on line 1 
Php :: php slots 
Php :: where post_type like 
Php :: traduction website with i18n 
Php :: codeigniter admin panel with crud generator - 
Php :: verify laravel string must be null 
Php :: upload laravel 
Php :: php header accept post request from same domain 
Php :: how to get session variables from cookie string 
Php :: Primary Termmaatwebsite/excel store s3 
Php :: Everything inside a pair 
Php :: wordpress add_action echo on edit page 
Php :: clear laravel cache and clear vue 
Php :: update php 7.2 centos 8 command line without sudo 
Php :: how to cut middle part of text php 
Php :: mongodb uploading csv php 
Php :: get_user_info 
Php :: pengulangan php 
Php :: command ui is not found 
Php :: omnipay capture 
Php :: PHP quoted_printable_decode — Convert a quoted-printable string to an 8 bit string 
Php :: php pop up message 
Php :: protocals supported by php 
Php :: launch new tab and refresh original page codeigniter 
Php :: laavel relation through morph 
Php :: CausesActivity trait 
Php :: trait class has consttoctor 
Php :: check if date is older than today php 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =