WordPress.org

Ready to get started?Download WordPress

Forums

Randomly show post attachment (1 post)

  1. sayagdan
    Member
    Posted 6 months ago #

    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 image that is directly attached to the current post.
    I want to show the posts / posts attachments in random order though i noticed that 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 blog.dansayag.com.

Reply

You must log in to post.

About this Topic