4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Sunny C. on June 15, 2010, 06:07:26 PM

Title: [MOD] Pictures of a specified category / Bilder einer bestimmten Kategorie anzei
Post by: Sunny C. on June 15, 2010, 06:07:26 PM
Open / Öffne: index.php
Search / Suche:
$site_template->register_vars("new_images", $new_images);
unset($new_images);
Add after / Füge danach ein:
//-----------------------------------------------------
//--- Show New Images By Category ---------------------
//-----------------------------------------------------
$imgtable_width = ceil(intval($config['image_table_width']) / $config['image_cells']);
if ((substr($config['image_table_width'], -1)) == "%") {
  $imgtable_width .= "%";
}

$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}

$num_news_images_bycat = $config['image_cells'];
// Option Start
$bycat_in = array(72,132); // Change the Number in your category-id - ID ripping by commas
                           // Ändere die Nummer in deine Kategorie-ID - ID trennen durch Komma
// Option Ende
$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").") AND i.cat_id IN (".implode(", ", $bycat_in).")
        ORDER BY i.image_date DESC
        LIMIT $num_news_images_bycat";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $news_images_bycat = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $news_images_bycat .= $lang['no_news_images_bycat'];
  $news_images_bycat .= "</td></tr></table>";
}
else  {
  $news_images_bycat = "<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;
      $news_images_bycat .= "<tr class=\"imagerow".$row_bg_number."\">\n";
    }
    $news_images_bycat .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

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

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

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

Suche nach // Option Start. Dort müssen die ID´s der Kategorien eingetragen werden
Search / / Start option. Where the ID's of the categories listed

Add this code in your home.html
Füge diesen Code in deiner home.html ein
{news_images_bycat}

Finish
Fertig
Title: Re: [MOD] See new pictures of a specified category
Post by: Sunny C. on June 26, 2010, 09:58:10 AM
Wie kann man das eiegntlich extern ausgeben lassen?
Title: Re: [MOD] See new pictures of a specified category
Post by: GaYan on July 05, 2010, 03:28:29 AM
great mod  :wink: cant we control this over the admin panel ;  its always pain to edit the code  :mrgreen: ! thanks !
Title: Re: [MOD] See new pictures of a specified category
Post by: khan on August 29, 2010, 11:55:30 PM
great and very useful mod, is there way to disply new images from all sub categories under a specified main category?

for example :
I have the main category "Main Category" and its sub ctegories "Sub Cat1>Sub Cat2>Sub Cat3>Sub Cat4>"   in the code (index.php) assign only the main category ID and the script disply new images from all its sub categories.

things are very much clear in your post i can get the result by adding all sub cats IDs but I frequently adding new sub categories under different Main Categories and its a bit difficult to add Cat IDs every time i add a new sub cat.
Title: Re: [MOD] See new pictures of a specified category
Post by: V@no on August 30, 2010, 04:00:34 AM
You can use something like this:
$main_cat_id = 123; //Main Category ID
$subcat_ids = array();
get_subcat_ids($main_cat_id, $main_cat_id, $cat_parent_cache);
$bycat_in = $subcat_ids[$main_cat_id];
Title: Re: [MOD] See new pictures of a specified category
Post by: khan on August 30, 2010, 08:56:51 PM
hi v@no!
i add the code after line
Code: [Select]
$bycat_in = array(my cat ID); but there is no output except a blank space. please let me know where i exactly place or replace the code.

Thanx
Title: Re: [MOD] See new pictures of a specified category
Post by: V@no on August 30, 2010, 09:09:29 PM
blank space? if anything, it should tell you that there is no images...or you mean blank page?
Title: Re: [MOD] See new pictures of a specified category
Post by: khan on August 30, 2010, 09:21:27 PM
i added th tag {news_images_bycat} on my home page, i have a main category ID = 2 and it has a sub cat ID = 8 when i assign sub cat ID directly to (   $bycat_in = array(my sub cat ID 8);  ) without adding your code it works and display the new images from that sub cat, but after adding the code i assign Main Cat ID which is in my case 2, there is nothing to display.

rest of the page is ok, every things are displying, my code is:
// Option Start

$bycat_in = array(2); // Change the Number in your category-id - ID ripping by commas

$main_cat_id = 2; //Main Category ID
$subcat_ids = array();
get_subcat_ids($main_cat_id, $main_cat_id, $cat_parent_cache);
$bycat_id = $subcat_ids;
// Option Ende
Title: Re: [MOD] See new pictures of a specified category
Post by: V@no on August 31, 2010, 02:29:06 AM
oopsy daisy  :oops:

Replace $bycat_id with $bycat_in
Title: Re: [MOD] See new pictures of a specified category
Post by: khan on August 31, 2010, 10:07:08 PM

same as before but now i get error message "An unexpected error occured. Please try again later."
Title: Re: [MOD] See new pictures of a specified category
Post by: V@no on September 01, 2010, 05:35:08 AM
hmmm apparently I forgot how that function works..
replace
$bycat_in = $subcat_ids;

With:
$bycat_in = $subcat_ids[$main_cat_id];
Title: Re: [MOD] See new pictures of a specified category
Post by: khan on September 01, 2010, 12:42:30 PM
Wow .... thanx v@no it works now
Title: Re: [MOD] See new pictures of a specified category
Post by: sigma. on December 29, 2010, 04:21:18 AM
exactly what i needed. Thanks!
Title: Re: [MOD] See new pictures of a specified category
Post by: nightfallsnet on January 04, 2011, 10:15:37 AM
hmm edited index.php and added {news_images_bycat} to home not showin anything.. 1.7.9
Title: Re: [MOD] See new pictures of a specified category
Post by: a1367h on December 20, 2012, 03:03:53 AM
Hi.
I want  to use it just for one category. when i set my category number, it just repeat one image in two rows and 4 columns same as new images number.(8 images)
I need 4 images in one row.
could anyone help me?

sorry for my bad English. I'm not expert in English.
I hope you understand what I  want.
Title: Re: [MOD] See new pictures of a specified category
Post by: .Infecto on October 20, 2014, 01:05:23 PM
Hallo,

ist es möglich das ganze etwas automatisch zu gestalten?

Im AdminCP ein Feld anlegen in dem man z.B die Kategorien mittels Trennung eines Kommas angeben kann (12,23,44)
Das System schreibt durch die Erkennung plus komma und zahl (,23) das eine weitere Kategorie angefragt werden soll und schreibt quasi den nötigen Code über dem "?>" in die index.php und der dazugehörigen Zahl "23" bzw. Kategorie-ID.
Ist das realisierbar?

Viele Grüße

Edit:

Hier mal der Code (Eventuell kann man das eleganter lösen)
// Option Start
$bycat_in = array(1,12,21);
// Option Ende
$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").") AND i.cat_id IN (".implode(",", $bycat_in).")
        ORDER BY i.image_date DESC
        LIMIT $num_new_media_cat";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
if (!$num_rows)  {
  $new_media_cat = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $new_media_cat .= $lang['no_new_media_cat'];
  $new_media_cat .= "</td></tr></table>";
}
else  {
  while ($image_row = $site_db->fetch_array($result)){
    show_image($image_row);
    $new_media_cat .= $site_template->parse_template("new_media_cat");
  } // end while
} // end else
$site_template->register_vars("new_media_cat", $new_media_cat);
unset($new_media_cat);
Hier werden die Kategorien abgefragt bzw. eingetragen:
$bycat_in = array(1,12,21);
Am elegantesten wäre, wenn man nun in diesem Abschnitt den Name mit der ID ergänzen könnte:
$new_media_cat .= $site_template->parse_template("new_media_cat");
Beispiel:
$new_media_cat .= $site_template->parse_template("new_media_cat_".$bycat_in);
Denn in den Templates verwende ich {new_media_cat} als Ausgabe, was auch ohne Probleme funktioniert. Schön wäre es, wenn ich {new_media_cat} dann mehrmals verwenden kann wie z.B so:
{new_media_cat_1}
{new_media_cat_12}
{new_media_cat_21}
Geht das überhaupt?

EDIT:
Keine Chance.... :(

//-----------------------------------------------------
//--- Show New Images By Category ---------------------
//-----------------------------------------------------

$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}
 $num_new_media_cat = $config['image_cells'];
// Option Start
$bycat_in = array(1,2,3);
foreach ($bycat_in as $var) {
// Option Ende
$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").") AND i.cat_id IN (".implode(",", $var).")
        ORDER BY i.image_date DESC
        LIMIT $num_new_media_cat";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $new_media_cat = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $new_media_cat .= $lang['no_new_media_cat'];
  $new_media_cat .= "</td></tr></table>";
}
else  {
    while ($image_row = $site_db->fetch_array($result)){
    show_image($image_row);
    $new_media_cat .= $site_template->parse_template("new_media_cat");
  } // end while
} // end else
    $site_template->register_vars("new_media_cat_" . $var . "", $new_media_cat);
}
unset($new_media_cat);
Title: Re: [MOD] See new pictures of a specified category
Post by: Sunny C. on October 21, 2014, 09:03:57 AM
Die Idee ist ganz cool.
So könnte man das dann dynmaisch ausgeben und muss nicht für jede Kategorie neuen Code benutzen.

Nicht getestet,
aber eventuell so?


$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}
 $num_new_media_cat = $config['image_cells'];
// Option Start
foreach (explode(',', '1,2,3') as $var) {
// Option Ende
$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").") AND i.cat_id IN (".$var.")
        ORDER BY i.image_date DESC
        LIMIT $num_new_media_cat";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $new_media_cat = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $new_media_cat .= $lang['no_new_media_cat'];
  $new_media_cat .= "</td></tr></table>";
}
else  {
    while ($image_row = $site_db->fetch_array($result)){
    show_image($image_row);
    $new_media_cat .= $site_template->parse_template("new_media_cat");
  } // end while
} // end else

$site_template->register_vars(array(
  "new_media_cat_" . $var . "" => $new_media_cat
));
}
unset($new_media_cat);
Title: Re: [MOD] See new pictures of a specified category
Post by: .Infecto on October 21, 2014, 11:10:29 AM
Hallo und Danke,

ich kann nun die variable

{new_media_cat_1}
{new_media_cat_2}
{new_media_cat_3}

Allerdings gibt er mir bei:
{new_media_cat_1}
Bilder aus cat_id 2 und 3 aus

Test: Papa 2
Test: Papa
Test: Hubba 3

Bei
{new_media_cat_2}
Gibt er mir die Bilder von id 2 und 3 doppelt aus :(

Test: Papa 2
Test: Papa
Test: Hubba 3
Test: Papa 2
Test: Papa
Test: Hubba 3

Bei variable _3 das dreifache

Test: Papa 2
Test: Papa
Test: Hubba 3
Test: Papa 2
Test: Papa
Test: Hubba 3
Test: Papa 2
Test: Papa
Test: Hubba 3

Hast du eine Idee?





....................

Ich komme hier nicht weiter :(


Edit://
Ich konnte das nun anders und automatisiert lösen.

Ich habe nun in der Übersicht der zu bearbeiteten Kategorien einen Link beigefügt, welcher automatisch den PHP-Code für weitere Kategorien erstellt und diese beliebig ausgibt. Man muss nichts mehr von Hand eingeben.

MFG