I have little problem in my wordpress template it showing me the the posts in decending form (the oldest posts showing first)
Is there any way to customize this code and add an orderby little function in it?
please help me in this

<?php

$i = 0; 

if ( empty($image_width) ) {
    if ( $columns == 1 )
        $image_width = 960;
    else 
        $image_width = 480;
}

if ( $image_ratio && $image_width ) {
    $image_height = cloudfw_match_ratio( $image_width, $image_ratio );  
}

$atts[ 'show_side_date_year' ] = false;


while( $posts->have_posts() ) : 
    $posts->the_post();
    $post_data = $this->get_post();

    /** Item number */
    $i++;
    $item_content = '';
    $item_classes = array();
    $item_classes[] = 'ui--blog-item ui--animation ui--accent-gradient-hover-parent clearfix';

    $item_classes[] = 'layout--' . $raw_layout;

    if ( $i == $post_count )
        $item_classes[] = 'last-item'; 

    $item_content .= "<div".
        cloudfw_make_class( $item_classes, true ) .
        ">";

        $link_element = array();
        $link_element[0]  = "<a class=\"ui--blog-link\" href=\"". $post_data['permalink'] ."\"";
        $link_element[0] .= ">";
        $link_element[1]  = "</a>";

        $item_content .= $this->side( $post_data, $atts );

        $item_content .= "<div class=\"ui--blog-content-wrapper\">";

            $item_content .= "<div class=\"ui--blog-header\">";
                $item_content .= "<{$title_element} class=\"ui--blog-title\">" . $link_element[0] . $post_data['title'] . $link_element[1] . "</{$title_element}>";   

                $metas = $this->get_blog_metas( $metas_primary, $post_data );
                $likes = $this->get_blog_metas( $metas_secondary, $post_data );

            $item_content .= "</div>";

            $excerpt = $this->get_excerpt( array('readmore' => $readmore, 'excerpt' => $show_excerpt, 'excerpt_length' => $excerpt_length, 'use_more_link' => false ) );
            if ( !empty($excerpt)) {
                $item_content .= "<div class=\"ui--blog-content\">";
                    $item_content .= $excerpt;
                $item_content .= "</div>";
            }

            $item_content .= "<div class=\"ui--blog-readmore more-link\">";
                $item_content .= "<a class=\"btn btn-small ". cloudfw_make_button_style( cloudfw_get_option( 'blog_template_mini',  'button_color', 'btn-secondary muted' ), true ) . "\" href=\"". $post_data['permalink'] ."\"";
                $item_content .= ">";
                    $item_content .= $readmore;
                $item_content .= "</a>";
            $item_content .= "</div>";

        $item_content .= "</div>";

    $item_content .= "</div>";

    if ( $columns > 1 ) {
        $column_array = array();
        $column_array['class'] = array();
        $column_array['_key'] = 'blog_mini';

        //$content_out .= $item_content;
        $content_out .= cloudfw_UI_column( $column_array, $item_content, '1of' . $columns . ( $i % $columns == 0 ? '_last' : '' ), $i == $post_count );
    } else {
        $content_out .= $item_content;
    }

endwhile;

Recommended Answers

All 6 Replies

not working

Can you explain what and why it doesn't work? If you don't give us details, we cannot help much.

@hallianonline,

Cereal, have provided more than enough to solve your problem and if you need more please follow link below..

another one for you. The answer to your question is located about 3/4 down the page.

This is only an example and you may need to research the codex for other stuff related to this subject matter.

before this

while( $posts->have_posts() ) : 

you need to set your arguments to something like ..;

$your_sort_requirements = array(

                            'order' => 'ASC',
                            'orderby' => 'whatever_you_want'.
                            ## define more here as you want
                            );


## and then you create an instance of the WP_query as mentioned on the codex.

$this_is_now_your_post_query = new WP_Query(  $your_sort_requirements);

since it is now your query, we can pretty much do this

if($this_is_now_your_post_query->have_posts()){

    while( $this_is_now_your_post_query->have_posts() ) : 

    ## do as what a good wordpress developer should do here..

    }
commented: perfect +2

Thanks friends after doing my research on your provided help,
I personally resolved my issue
Stay happy both of you.
Thanks once again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.