Author Topic: (req Mod) new start page  (Read 6175 times)

0 Members and 1 Guest are viewing this topic.

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
(req Mod) new start page
« on: April 05, 2005, 08:31:14 AM »
Hello
how could code a start page likt this

http://www.foto-kocher.com/start.htm

i think the code should be like this!

1) Random Category with more then x Picture // x is a number say 30
2) Random 6 Picture frome this in 1) defined Category

sincerly
vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline martrix

  • Hero Member
  • *****
  • Posts: 755
    • View Profile
    • overlord.cz
Re: (req Mod) new start page
« Reply #1 on: April 15, 2005, 11:26:19 AM »
Photogallerie => Photogallery  :wink:
MAяTRIX


Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: (req Mod) new start page
« Reply #2 on: April 15, 2005, 11:48:33 AM »
yepp english is not easy at all!

but changed it - i hope you know the rest of the code  :wink:

 8O vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: (req Mod) new start page
« Reply #3 on: June 07, 2005, 11:15:26 AM »
moving up this request
maybe i could also define which categorie i would like to have 6 random picture

sincerly vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods


Offline edwin

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • http://www.foto-janssen.nl
Re: (req Mod) new start page
« Reply #4 on: June 07, 2005, 11:28:18 AM »
Yes, i'm looking for this too

Offline rroc

  • Pre-Newbie
  • Posts: 8
    • View Profile
Suggestion: [Mod] random category images start page
« Reply #5 on: June 22, 2005, 05:33:05 PM »
Hi,
I thought this should be an easy one... well, I think the following should work... I didn't test it though as I don't need it. :)  So I won't put it to a 'real' MOD directory before someone has tested it and found it working.... Good luck. : )

So this checks which categories are under the given(default=main) category and picks one of them. From that category  it will pick 10 images, which are shown... At least in theory...


As before, backup following:
functions.php
index.php
home.html



Add a new funcktion to functions.php

Code: [Select]
function get_random_cat_random_images($cat_id = 0, $amount_total = 1)
{
global $site_template, $site_db, $site_sess, $config, $lang;
global $cat_cache, $cat_parent_cache, $new_image_cache, $subcat_ids;

$cattable_width = ceil((intval($config['cat_table_width'])) / $config['cat_cells']);
if ((substr($config['cat_table_width'],-1)) == "%")
{
$cattable_width .= "%";
}

if (!isset($cat_parent_cache[$cat_id]))
{
return "";
}

$visible_cat_cache = array();
foreach ($cat_parent_cache[$cat_id] as $key => $val)
{
if (check_permission("auth_viewcat", $val))
{
$visible_cat_cache[$key] = $val;
}
}
if (empty($visible_cat_cache))
{
return "";
}

$total = sizeof($visible_cat_cache);

$count = 0;
$count2 = 0;
srand((float)microtime() * 1000000);
$category_id = array_rand($visible_cat_cache);

$is_new = (isset($new_image_cache[$category_id]) && $new_image_cache[$category_id] > 0) ? 1 : 0;
$num_images = (isset($cat_cache[$category_id]['num_images'])) ? $cat_cache[$category_id]['num_images'] : 0;

$subcat_ids = array();
get_subcat_ids($category_id, $category_id, $cat_parent_cache);

if (isset($subcat_ids[$category_id]))
{
foreach ($subcat_ids[$category_id] as $val)
{
if (isset($new_image_cache[$val]) && $new_image_cache[$val] > 0)
{
$is_new = 1;
}
if (isset($cat_cache[$val]['num_images']))
{
$num_images += $cat_cache[$val]['num_images'];
}
}
}

for($amount=0;$amount<$amount_total;$amount++)
{
if (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0 ||
  defined("SHOW_RANDOM_CAT_IMAGE") && SHOW_RANDOM_CAT_IMAGE == 0)
{
$random_cat_image_file[$amount] = "";
}
else
{
$randimage = get_random_image($category_id, 0, 1);
if((array_search($randimage, $random_cat_image_file)===FALSE /*NULL for PHP version<4.2*/)
{
$random_cat_image_file["random_cat_image_file".$amount] = $randimage;
}
else
{
$amount--;
}
}
   }
$vars = array(
  "cat_id" => $category_id,
  "cat_name" => $cat_cache[$category_id]['cat_name'],
  "cat_description" => $cat_cache[$category_id]['cat_description'],
  "cat_hits" => $cat_cache[$category_id]['cat_hits'],
  "cat_is_new" => $is_new,
  "lang_new" => $lang['new'],
  "sub_cats" => get_subcategories($category_id),
  "cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
  "num_images" => $num_images
  );
$vars = array_merge($vars, $random_cat_image_file);

$site_template->register_vars($vars);
$category_random = $site_template->parse_template("category_random");
return $category_random;
}

CREATE a html file
category_random.html, with the desired layout similar to category_bit.html, here for 10 images...
Code: [Select]
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top">
      {if random_cat_image_file0}
      <a href="{cat_url}"><img src="{random_cat_image_file0}" border="1"></a><br>
      {endif random_cat_image_file0}{if random_cat_image_file1}
      <a href="{cat_url}"><img src="{random_cat_image_file1}" border="1"></a><br>
      {endif random_cat_image_file1}{if random_cat_image_file2}
      <a href="{cat_url}"><img src="{random_cat_image_file2}" border="1"></a><br>
      {endif random_cat_image_file2}{if random_cat_image_file3}
      <a href="{cat_url}"><img src="{random_cat_image_file3}" border="1"></a><br>
      {endif random_cat_image_file3}{if random_cat_image_file4}
      <a href="{cat_url}"><img src="{random_cat_image_file4}" border="1"></a><br>
      {endif random_cat_image_file4}{if random_cat_image_file5}
      <a href="{cat_url}"><img src="{random_cat_image_file5}" border="1"></a><br>
      {endif random_cat_image_file5}{if random_cat_image_file6}
      <a href="{cat_url}"><img src="{random_cat_image_file6}" border="1"></a><br>
      {endif random_cat_image_file6}{if random_cat_image_file7}
      <a href="{cat_url}"><img src="{random_cat_image_file7}" border="1"></a><br>
      {endif random_cat_image_file7}{if random_cat_image_file8}
      <a href="{cat_url}"><img src="{random_cat_image_file8}" border="1"></a><br>
      {endif random_cat_image_file8}{if random_cat_image_file9}
      <a href="{cat_url}"><img src="{random_cat_image_file9}" border="1"></a><br>
      {endif random_cat_image_file9}
     
  <a href="{cat_url}" class="maincat">{cat_name}</a>&nbsp;({num_images})
      {if cat_is_new}<sup class="new">{lang_new}</sup>{endif cat_is_new}
</td>
  </tr>
</table>
{if cat_description}<span class="smalltext">{cat_description}</span><br />{endif cat_description}
{if sub_cats}{sub_cats}{endif sub_cats}

index.php
FIND:
Code: [Select]
unset($categories);ADD below:
Code: [Select]
//-----------------------------------------------------
//--- Show Category random images ---------------------------------
//-----------------------------------------------------
$cat_random_images = get_random_cat_random_images(0,10);
if (!$cat_random_images)  {
  $cat_random_images = $lang['no_categories'];
}
$site_template->register_vars("cat_random_images", $cat_random_images);
unset($cat_random_images);

And in home.html
REPLACE:
Code: [Select]
                  {if categories}
                  <table width="450" border="0" cellspacing="0" cellpadding="1">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                          <tr>
                            <td class="head1" valign="top">{lang_categories}</td>
                          </tr>
                          <tr>
                            <td class="row2" valign="top">{categories}</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                  <br />
                  {endif categories}

BY:
Code: [Select]
                  {if cat_random_images}
                  <table width="450" border="0" cellspacing="0" cellpadding="1">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                          <tr>
                            <td class="head1" valign="top">{lang_categories}</td>
                          </tr>
                          <tr>
                            <td class="row2" valign="top">{cat_random_images}</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                  <br />
                  {endif cat_random_images}