4images Modifications / Modifikationen > Mods & Plugins (Requests & Discussions)

Random pictures

(1/31) > >>

joecks:
Hi all,

Is it possible to add a section "random Images" on the index page, below or above the new pictures ? and a section "most popular" ???

I have that option in photopost pro, but this program is not working when safe mode is on  :cry: (shame for a $149 product !) , thats why is use the great free program 4images now.

Great Program!

Grtx,

Joecks

SLL:
"random picture" is already there by default, the "most popular" you can find in the this forum, in mod's section (photo of the day)

joecks:
I know there is a random picture, but i want to know if it is posible to ad random pictures on the index page below or above the new images, not just 1 random picture but as many as the new pictures..

same for the most popular pictures.

for a example see this featured site of photopost, http://www.spymac.com/gallery/

than you see what i mean.

Thanx

Carlo

SLL:
if you mean showing random pics at any page, not inside 4images - this mod you also can find in mod's section of this forum

V@no:
Open index.php
Find:
--- Code: ---$site_template->register_vars("new_images", $new_images);
unset($new_images);
--- End code ---

Add after:

Version A (without cache, images will be randomize on each visit, each page refresh)
//------------------------------------
//------- Random Images --------------
//------------------------------------
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY RAND()
        LIMIT $num_new_images";
// end new
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
//  $random_images .= $lang['no_new_images'];
  $random_images .= "</td></tr></table>";
}
else  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $random_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";
    }
    $random_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

    show_image($image_row);
    $random_images .= $site_template->parse_template("thumbnail_bit");
    $random_images .= "\n</td>\n";
    $count++;
    if ($count == $config['image_cells']) {
      $random_images .= "</tr>\n";
      $count = 0;
    }
  } // end while

  if ($count > 0)  {
    $leftover = ($config['image_cells'] - $count);
    if ($leftover >= 1) {
      for ($f = 0; $f < $leftover; $f++) {
        $random_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
      }
      $random_images .= "</tr>\n";
    }
  }
  $random_images .= "</table>\n";
} // end else


$site_template->register_vars("random_images", $random_images);
unset($random_images);

//----- End Random Images---------

Version B (with cache, images will be randomize once each hour, time controlled by $cache_time on top of the code.)
//------------------------------------
//------- Random Images --------------
//------------------------------------
$cache_time = 3600; //3600sek = 1hour

$cache_enable_old = $cache_enable;
$cache_enable = true;
$cache_id_rand = create_cache_id(
  'page.rand',
  array(
    $user_info[$user_table_fields['user_id']],
    isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
    $config['template_dir'],
    $config['language_dir']
  )
);
if (!$random_images = get_cache_file($cache_id_rand, $cache_time))
{
  // Always append session id if cache is enabled
  $old_session_mode = $site_sess->mode;
  $site_sess->mode = 'get';
  $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
          FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
          LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
          WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
          ORDER BY RAND()
          LIMIT $num_new_images";
  // end new
  $result = $site_db->query($sql);
  $num_rows = $site_db->get_numrows($result);
  
  if (!$num_rows)  {
    $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  //  $random_images .= $lang['no_new_images'];
    $random_images .= "</td></tr></table>";
  }
  else  {
    $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
    $count = 0;
    $bgcounter = 0;
    while ($image_row = $site_db->fetch_array($result)){
      if ($count == 0) {
        $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
        $random_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";
      }
      $random_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";
  
      show_image($image_row);
      $random_images .= $site_template->parse_template("thumbnail_bit");
      $random_images .= "\n</td>\n";
      $count++;
      if ($count == $config['image_cells']) {
        $random_images .= "</tr>\n";
        $count = 0;
      }
    } // end while
  
    if ($count > 0)  {
      $leftover = ($config['image_cells'] - $count);
      if ($leftover >= 1) {
        for ($f = 0; $f < $leftover; $f++) {
          $random_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
        }
        $random_images .= "</tr>\n";
      }
    }
    $random_images .= "</table>\n";
  } // end else
  $site_sess->mode = $old_session_mode;
  save_cache_file($cache_id_rand, $random_images);
}
$cache_enable = $cache_enable_old;
$site_template->register_vars("random_images", $random_images);
unset($random_images);

//----- End Random Images---------



Now, in home.html template add {random_images}

Navigation

[0] Message Index

[#] Next page

Go to full version