简体   繁体   中英

Wordpress/PHP: Can't get WordPress posts to order by year/date

I've grouped my posts by year...but it's showing the earliest yearsection first eg 2013 and not 2015...

2013 2014 2015

It shoul dbe

2015 2014 2013

Here is the code:

$year_check = date('Y', strtotime($post->post_date));
            if($year_tmp!==$year_check){
                $year_tmp = $year_check;

                if($postsShown > 0){
                    echo '</div>';
                }

                echo '<div class="seperator"></div><a href="#" class="datecolumn" id="date_col_'.$year_check.'">'.$year_check.'<div class="expand" id="expand_'.$year_check.'">CLOSE</div></a><div class="seperator"></div><div class="ruler"></div><div class="seperator"></div><div class="yearBlock" id="'.$year_check.'">';
            }

            $date = date('jS F Y', strtotime($post->post_date));

            echo '<a class="standardColumnLink" href="'.get_permalink($post->ID).'" title="'.$thetitle.'">';

            if(!empty($thethumb)){
                echo '<div class="standardColumnImage">'.$thethumb.'</div>';
            }

            echo '<div class="columncopy"><div class="narrowcolumn">&rarr;</div><div class="titles">'.$thetitle.'</div><div class="columnbody">'.get_excerpt_by_id(get_the_ID()).'</div><div class="columdate"><strong>Date posted:</strong> '.$date.'</div></div></a>';

            if($year_tmp!==$year_check){
                echo '</div>';
            }

You're absolutely right, it was i the query logic... I changed the orderby to DESC and it worked.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM