• Resolved elyonline

    (@elyonline)


    Hey all,

    I know this is a big ask bust I am trying to workout how I can randomize the following code (from Justin Tadlock) I have. This code currently pulls a video based on a custom field from a post. What I would dearly love is for the script to randomize any posts that has the custom field. I have been searching high and low but as of yet have found no tutorial.

    Can anyone help please?

    Thank you


    <?php
    // This file displays the latest video article on the front page
    rewind_posts();
    // Query one post from “video” category
    $my_query = new WP_Query(‘category_name=video&showposts=1’);
    while ($my_query->have_posts()) : $my_query->the_post();
    // Get the “Video” custom field Key as an array (displays single Value in the video block)
    $video = get_post_custom_values($key = ‘video-value’);
    ?>

    <h5>” title=”<?php the_title(); ?>”><?php the_title(); ?></h5>

    <div class=”<?php echo $i; ?>video”>
    <div>
    <?php
    // Check to see if custom field “Video” is set and if it has anything in the “Value” field.
    if(isset($video[0]) && strcmp($video[0],”)!= 0) {
    // Display valid XHTML player for YouTube, Google, MetaCafe, and other video sites
    // “echo $video[0];” displays the first item in the array for the custom field “Video”
    ?>

    <object type=”application/x-shockwave-flash” data=”<?php echo $video[0]; ?>” style=”width: 290px; height: 242px; border: none; padding: 0; margin: 0;” id=”video-block-<?php echo $i; ?>”>
    <param name=”movie” value=”<?php echo $video[0]; ?>” />
    <param name=’wmode’ value=’transparent’ />
    <param name=”quality” value=”best” />
    <param name=”bgcolor” value=”transparent” />
    <param name=”FlashVars” value=”playerMode=embedded” />
    </object>

    <?php } // endif

    // If there is no Value for the custom field Key “Video”
    else {

    // echo error checking to check custom field errors
    echo ‘Did not add a video URL to the custom field Key of “Video”‘;
    echo ‘<!– This user did not add the video URL to the correct custom field –>’;

    } // endelse
    ?>
    </div>
    </div> <!– video –>

Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘help on how to randomize posts’ is closed to new replies.