Arranging Images

images php coding issues or problems here.

Moderators: macek, egami, gesf

saber210
New php-forum User
New php-forum User
Posts: 1
Joined: Thu May 05, 2011 2:26 am

Arranging Images

Postby saber210 » Thu May 05, 2011 2:32 am

Hello their php-forum.. Im new here.. I new to php and im currently editing some wordpress themes.. I have on major problem. I found this code on the theme that will give random images on the post.. But I failed to tweak it.. The layout shows 6 by 2 of random post.. I just want to make it 3 by 3

This is the code:

Code: Select all

    <div id="random">
    <h3><?php _e('Random Posts','arthemia');?></h3>
   
    <?php $width = get_settings ( "cp_thumbWidth_Gallery" );
      $height = get_settings ( "cp_thumbHeight_Gallery" );
      if ( $width == 0 ) { $width = 80; }
      if ( $height == 0 ) { $height = 80; }
        $status = get_settings ( "cp_thumbAuto" );
   ?>
   
    <?php $randompost = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 9");

      foreach ($randompost as $post) {    
         $ID = $post->ID;
            $postid = get_post($post->ID);
            $title = $postid->post_title;
            $values = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $ID AND meta_key = 'Image' ");
            ?>   
   
    <?php if ( $status != "first" ) { ?>

   <?php
   if (isset($values)) {
   ?>
      <a href="<?php echo get_permalink($postid); ?>" rel="bookmark" title="<?php echo $title; ?>"><img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
echo $values; ?>&amp;w=<?php echo $width; ?>&amp;h=<?php echo $height; ?>&amp;zc=1&amp;q=100"
alt="<?php echo $title; ?>" class="left" width="<?php echo $width; ?>px" height="<?php echo $height; ?>px"  /></a>
      <?php } ?>

   <?php } else { ?>

   <?php $id =$post->ID;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$home = get_option('home');
$pattern = '!<img.*?src="'.$home.'(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0]; ?>
            
   <?php if($image_src != '') { ?><a href="<?php echo get_permalink($postid); ?>" rel="bookmark" title="<?php echo $title; ?>">
<img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo $image_src; ?>&amp;w=<?php echo $width; ?>&amp;h=<?php echo $height; ?>&amp;zc=1&amp;q=100"
    alt="<?php echo $title; ?>" class="left" width="<?php echo $width; ?>px" height="<?php echo $height; ?>px"  /></a><?php } ?>

   <?php } ?>
       
      <?php } ?>
    <div class="more" style="margin-top:-10px;padding-right:15px;font-weight:bold;float:right;"><a href="javascript:location.reload()" target="_self"><?php _e('(refresh random posts)','arthemia');?></a></div>
       
    </div>


Hope you can help me.. I tried to edit it on CSS but it always show on a 6 by 2..

Another question there is a limit on mysql query.. Is there a minimum? For example it will always show minimum images?

Sorry for my english.. Please help me.. Thanks!

Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 2 guests