Randomly show post attachment

  • Unknown's avatar

    Hi
    The best way to explain is to show my code :

    <?php
    if (have_posts()) :
    $c = 0; while ( have_posts() ) : the_post(); $c++;
    if ( $c == 1) {
    $style = “current first”;
    }
    elseif ( $c == count( $posts ) ) {
    $style = “last”; } /*
    elseif ( $c == 2 ) {
    $style = “”; }*/

    else $style =’dispa’;

    ?><?php
    $images =& get_children( array (
    ‘post_parent’ => $post->ID,
    ‘post_type’ => ‘attachment’

    ));
    foreach ( $images as $attachment_id => $attachment ) {

    ?><div <?php post_class($style) ?>id =”post_<?php echo $post->ID;?>”><?php echo wp_get_attachment_image( $attachment_id, ‘large’ ); }

    ?><div <?php post_class(‘mezzanine ‘ . $style) ?>><?php $description = $attachment->post_content;
    echo $description;
    ?></div></div><?php
    endwhile;
    wp_reset_postdata();
    else :
    echo wpautop( ‘Sorry, no posts were found’ );
    endif;
    ?>

    The result of this is to show the attachement link to the post.
    I want to show the posts in random order but adding the ‘orderby’ => ‘rand’ function is not helping.
    Does anyone could help me with this?
    Thank you in advance

    if you want to see the actual result you can go on http://blog.dansayag.com

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    The site you’ve linked to blog.dansayag.com is not hosted here on WordPress.com so we will not be able to help you.

    For help with your standalone WordPress install, please head over to http://wordpress.org/support/

    If you want to better understand the difference between WordPress.com and WordPress, you’ll want to read this support doc: http://support.wordpress.com/com-vs-org/

  • The topic ‘Randomly show post attachment’ is closed to new replies.