Author Topic: Most rated image from each category. How?  (Read 8180 times)

0 Members and 1 Guest are viewing this topic.

Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Most rated image from each category. How?
« on: October 20, 2008, 06:33:26 AM »
Hello,
I saw some mods for different tops, but not exactly what I need.
I want to put all most rated images from each category in one category/page.
How can I do that?

Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Re: Most rated image from each category. How?
« Reply #1 on: October 20, 2008, 01:42:27 PM »
OK,solved!
I did it by myself

Offline karoas

  • Pre-Newbie
  • Posts: 2
    • View Profile
Re: Most rated image from each category. How?
« Reply #2 on: January 12, 2010, 09:53:07 AM »
Could you some help to me, how did you do it that? I need that so much.

thank you.

Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Re: Most rated image from each category. How?
« Reply #3 on: January 20, 2010, 01:37:16 AM »
This is kind of top-photos, but the principle of selection is slightly different from the standard. For me it was important to select from each category just one photo with the highest rating.

displayed on a separate page
design as a category page

1. the file includes/page_header.php

find
Code: [Select]
"url_captcha_image" => $site_sess->url(ROOT_PATH."captcha.php"),
insert below
Code: [Select]
  "url_top_rated" => $site_sess->url(ROOT_PATH."top_rated.php"),
  "lang_top_rated" => $lang['top_rated'],


2. the file lang/your_lang/main.php

before ?> add

Code: [Select]
$lang['top_rated'] = "Top Rated";
$lang['top_rated_desc'] = "Here is one photo from each category with the highest rank.";

 :) My English isn't good, so change a name and description, if necessary.


3. a new file top_rated.php

save it in the root of gallery

Code: [Select]
<?php
/* --------- Most rated imade from each category on one page with paging ----------------- */


$templates_used 'top_rated,thumbnail_bit';
$main_template 'top_rated';

define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');

$cache_id create_cache_id(
  
'page.top_rated',
  array(
    
$user_info[$user_table_fields['user_id']],
    
$cat_id,
    
$page,
    
$perpage,
    isset(
$user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 08) : 0,
    
$config['template_dir'],
    
$config['language_dir']
  )
);

if (!
$cache_page_top_rated || !$content get_cache_file($cache_id)) {
// Always append session id if cache is enabled
if ($cache_page_top_rated) {
  
$old_session_mode $site_sess->mode;
  
$site_sess->mode 'get';
}

ob_start();

//-----------------------------------------------------
//--- Show Images -------------------------------------
//-----------------------------------------------------

  
$sql "SELECT cat_id
          FROM "
.IMAGES_TABLE."
          WHERE cat_id NOT IN ("
.get_auth_cat_sql("auth_viewcat""NOTIN").")
          GROUP BY cat_id"
;
  
$result $site_db->query($sql);
    
$num_rows_all mysql_num_rows($result);

$link_arg $site_sess->url(ROOT_PATH."top_rated.php");

include(
ROOT_PATH.'includes/paging.php');
$getpaging = new Paging($page$perpage$num_rows_all$link_arg);
$offset $getpaging->get_offset();

$site_template->register_vars(array(
  
"paging" => $getpaging->get_paging(),
  
"paging_stats" => $getpaging->get_paging_stats()
));

$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 .= ", a.".$key;
  }
}

$sql "SELECT a.image_id, a.cat_id, a.user_id, a.image_description, a.image_keywords, a.image_date, a.image_active, a.image_media_file, a.image_thumb_file, a.image_download_url, a.image_allow_comments, a.image_comments, a.image_downloads, a.image_votes, a.image_hits".$additional_sql.", a.image_name, c.cat_name
    FROM ("
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." c)
                WHERE a.image_active = 1 AND a.cat_id NOT IN ("
.get_auth_cat_sql("auth_viewcat""NOTIN").") AND a.image_votes != 0 AND a.image_rating = (SELECT MAX(image_rating)
                FROM  "
.IMAGES_TABLE." b
                WHERE a.cat_id= b.cat_id)
                GROUP BY a.cat_id
                ORDER BY "
.$config['image_order']." ".$config['image_sort']."
                LIMIT 
$offset$perpage";

$result $site_db->query($sql);
$num_rows $site_db->get_numrows($result);

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

    
show_image($image_row);
    
$thumbnails .= $site_template->parse_template("thumbnail_bit");
    
$thumbnails .= "\n</td>\n";

    
$count++;
    if (
$count == $config['image_cells']) {
      
$thumbnails .= "</tr>\n";
      
$count 0;
    }
  } 
// end while

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

//-----------------------------------------------------
//--- Clickstream ------------- -----------------------
//-----------------------------------------------------
$clickstream "<span class=\"clickstream\"><a title=\"".$lang['home']."\" href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$lang['top_rated']."</span>";

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------

$site_template->register_vars(array(
    
"top_rated_desc" => $lang['top_rated_desc'],
  
"msg" => $msg,
  
"clickstream" => $clickstream,
));

$site_template->print_template($site_template->parse_template($main_template));

$content ob_get_contents();
ob_end_clean();

if (
$cache_page_top_rated) {
  
// Reset session mode
  
$site_sess->mode $old_session_mode;

  
save_cache_file($cache_id$content);
}

// end if get_cache_file()

echo $content;

include(
ROOT_PATH.'includes/page_footer.php');
?>


4. a new file top_rated.html

4.1 to save design of gallery, open your file categories.html  and save it as top_rated.html

4.2 find 3 times
Code: [Select]
random_cat_image
replace with
Code: [Select]
random_image
4.3 find
Code: [Select]
{cat_name}
replace with
Code: [Select]
{lang_top_rated}
4.4 find and delete
Code: [Select]
{upload_button}
4.5 find
Code: [Select]
{cat_description} (Hits: {cat_hits})
replace with
Code: [Select]
{top_rated_desc}
4.6 find and remove all from (if categories) and to (endif categories) inclusive


5. for a link to this page anywhere on the site

use
Code: [Select]
<a href="{url_top_rated}">{lang_top_rated}</a>

Offline tennis-ecards

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Most rated image from each category. How?
« Reply #4 on: April 02, 2016, 01:44:58 AM »
Prima MOD!
Ich habe nur ein Problem. Der eingeblendete Kategorie-Name (cat_name) ist nicht korrekt (es steht überall der gleiche Name). Der Link zur Kategorie funktioniert hingegen richtig.
Woran kann das liegen und wie kann man das beheben?
Danke vorab.