WordPress.org

Ready to get started?Download WordPress

Forums

Change this loop to display RAND posts? (2 posts)

  1. neodan
    Member
    Posted 1 year ago #

    <?php
    global $data, $is_blog,$is_portfolio,$is_category,$is_search;
    $is_contact_page = false;
    $optionss =isset($post->ID)? get_post_meta($post->ID, 'themeton_additional_options', true):false;
    if($optionss===false){ unset($optionss);}
    
    $paged=isset($_REQUEST['infPaged'])?$_REQUEST['infPaged']:1;
    
    if($is_category===true){
        $category = get_query_var('cat');
    }
    if($is_search===true){
        $search = get_query_var('s');
    }
    
    //////////////////ABOUT PAGE//////////////////////
    if(get_ID_by_slug($data['first_page']) && ($is_portfolio===true || $is_blog===true) && !isset($_REQUEST['infPaged'])){
        query_posts( 'page_id='.get_ID_by_slug($data['first_page']) );
        while (have_posts ()) : the_post();
            get_template_part('post');
        endwhile;
        wp_reset_query();
    }
    
    //////////////////POSTS///////////////////////////
    if($is_blog===true || $is_portfolio===true){
        //Blog page && Portfolio page
        $tt_query = "";
        if(isset($optionss['posts_perpage'])){
            $tt_query .= "posts_per_page=" . $optionss['posts_perpage'];
        }
        if (isset($optionss['blog_categories'])) {
            $includecats = implode(',', (array) $optionss['blog_categories']);
            $includecats = $includecats ? "&category_name='" . $includecats . "'" : '';
            $tt_query .= $includecats;
        }
        $query=$tt_query;
    }elseif($is_category===true){
        $query='cat='.$category;
    }elseif($is_search===true){
        $query='s='.$search;
    }else{
        $query='';
    }
    
    $query.="&paged=$paged";
    
    if(isset($query)&&$query){
        query_posts( $query );
    }
    while (have_posts ()) : the_post();
        get_template_part('post');
    endwhile;
    wp_reset_query();
    
    //////////////////CONTACT PAGE////////////////////
    if(get_ID_by_slug($data['last_page']) && ($is_portfolio===true || $is_blog===true) && !isset($_REQUEST['infPaged'])){
        query_posts( 'page_id='.get_ID_by_slug($data['last_page']) );
        while (have_posts ()) : the_post();
            get_template_part('post');
        endwhile;
        wp_reset_query();
    }
    ?>

    What part do I have to edit to get random posts?

  2. neodan
    Member
    Posted 1 year ago #

    bump

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.