Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter icfriend

    (@icfriend)

    I really haven’t been able to knock this out. Anybody out there have any examples or know how to select 16 specific posts and have them display randomly, while all other posts are unaffected?

    Thread Starter icfriend

    (@icfriend)

    Thank you for this alchymyth. I’ve been working on it quite a bit today. This seems like the type of thing that if someone knows what they’re doing it takes 3 minutes, but for someone who doesn’t have the experience knocking code around it’s a challenge.

    Thread Starter icfriend

    (@icfriend)

    Dropping this code in now makes the right number of posts per page appear and the “older posts” link on the bottom of the page is back, but it is still showing random posts from all of the categories, sometimes displaying the same post 4 or 5 times on the page.

    <?php
    $args = array( 'orderby' => 'rand', 'post_status' => 'publish', );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    <?php endforeach; ?>

    I’m getting closer. I tried bringing in another loop after this one, but I can’t get anything that really works yet.

    Thread Starter icfriend

    (@icfriend)

    So I’m trying to drop in the first code in the index.php file below: <?php while (have_posts()) : the_post(); ?>

    I’ll have to tweek it quite a bit. I removed this section because I don’t know what it wants:
    ~Post-related code and template tags go here. ~

    The code I posted earlier is making everything completely random. All of the posts from all of the categories are random, sometimes displaying the same post 4 or 5 times on the page. It also shows a random number of posts on the page. It even removed the “older posts” link at the bottom.

    I’ll need to search for “a regular query with a limit of 7” I don’t quite follow.

    Thanks for your help!

    Thread Starter icfriend

    (@icfriend)

    Another way to describe the problem that may make a solution easier. I have 23 posts from a category titled “Web Site”. I want the original seven to continue to show normally. But, out of the most recent 16, I only want one to display at a time.

    I can’t even begin to wrap my mind around it, but I know from just looking at the .php I’ve seen that it has to be possible,. Out of everything I’ve tried, it must be the easiest solution.

    Thread Starter icfriend

    (@icfriend)

    The IDs don’t show up in the URL. Each post has it’s own slug, I.E = …./blog/2011/07/19/frame-episode-9/
    …./blog/2011/06/18/new-leadership-keynote/
    …./blog/2007/05/02/community-radio-licenses/

    Would it be something like this?

    <?php
    $rand_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT 1");
    query_posts("p=$rand_id");
    ?>
    <?php while (have_posts()) : the_post(); ?>
    
    ~Post-related code and template tags go here. ~
    
    <?php endwhile; ?>
Viewing 6 replies - 1 through 6 (of 6 total)