4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: abman5 on August 16, 2009, 03:01:46 PM

Title: How to shows Categories anywhere ?
Post by: abman5 on August 16, 2009, 03:01:46 PM
Code: [Select]
//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
$categories = get_categories(0);
if (!$categories)  {
  $categories = $lang['no_categories'];
}
$site_template->register_vars("categories", $categories);
unset($categories);

If I place the upper codes in any php file then it shows Categories list on that page. It is really cool, cause I have not to write full code in every page where I want to show it.

But i don't know how its work and where the original code comes from. I asking this question because I want to show a (same) ads in various pages. So I want to make a system like 'Show Categories', so that a small code for various page acts like full code for displaying ads.

Please tell me how 'Show Categories ' builded and linked with which code?
Also can tell system to create 'Show Ads' like 'Show Categories '
Title: Re: How to shows Categories anywhere ?
Post by: abman5 on August 17, 2009, 03:14:07 PM
Nobody can't help ??

UNBELIEVEABLE
Title: Re: How to shows Categories anywhere ?
Post by: V@no on August 17, 2009, 03:24:29 PM
It only passed 24 hours since your question and you already inpatient. This is a forum, not a chat room ;)

Your question is not so easy to answer. Well, technically it's easy to answer, because the answer is:
get_categories() function is in includes/functions.php
and template class is in includes/templates.php

but that doesn't help much, now does it?

Try explain with more details what exactly you are trying to do and how you think it should looks like.
Title: Re: How to shows Categories anywhere ?
Post by: bash-t on August 17, 2009, 05:56:05 PM
...But i don't know how its work and where the original code comes from. ...

A very useful tool for windows users for this matter:

http://www.wingrep.com/ (an adaptation of the 'grep' of the linux world http://de.wikipedia.org/wiki/Grep )

With this tool you can search the entire project folder for some special phrase e.g. get_categories(0)

So you can easily figure out where the code comes from. (I made my way through the code in this way ;) )

Regards,
Bash-T
Title: Re: How to shows Categories anywhere ?
Post by: abman5 on August 23, 2009, 11:02:11 AM
V@no,

I solved this by myself.
But a problem is, its work on "a_example_page.php" but if the url is "a_example_page.php?id=abc" then content doesn't show.

I didn't find get_categories() in template.php

Why these lines used for in function.php?
Code: [Select]
  global $site_template, $site_db, $site_sess, $config, $lang;
  global $cat_cache, $cat_parent_cache, $new_image_cache, $subcat_ids;
Title: Re: How to shows Categories anywhere ?
Post by: V@no on August 24, 2009, 03:15:00 AM
But a problem is, its work on "a_example_page.php" but if the url is "a_example_page.php?id=abc" then content doesn't show.
Sorry, but you didn't give enough information about what you are trying to do (ok topic's headline gives some clues) and what you've done so far.. I really don't know what the ID supposed to represent, how you are using it and what is the exact result.

I didn't find get_categories() in template.php
because it's in includes/functions.php

Why these lines used for in function.php?
Code: [Select]
 global $site_template, $site_db, $site_sess, $config, $lang;
  global $cat_cache, $cat_parent_cache, $new_image_cache, $subcat_ids;
hmmmm because these variables are used by the function...or your question is about global (http://php.net/manual/en/language.variables.scope.php#language.variables.scope.global) keyword?
Title: Re: How to shows Categories anywhere ?
Post by: abman5 on August 24, 2009, 09:59:00 AM
V@no,

HERE IS FULL EXPLANATION:

I want to show my 'personalized category menu' in entire site (whole pages) like bellow.

My Category
  Funny
  Animal
  Birds
  Flower
  Paint

Category names comes from a sql table (structure like bellow).

  Cate_name
  ---------------
  Funny
  Animal
  Birds
  Flower
  Paint

I used following code in includes/functions.php

Code: [Select]
function get_mycategory() {
  global $site_db, $lang;

  $sql = "SELECT cate_name FROM table";
  $res = $site_db->query($sql);
  $num_rows = $site_db->get_numrows($res);

  $mycate .= "<ul>";

  if ($num_rows) {
    while($row = $site_db->fetch_array($res)) {
      $mycate .= "<li><a href=\"mycategory.php?brand=$row[cate_name] \">$row[cate_name]</a></li>";
    }
  }
  else {
    $mycate .= $lang['no_cate'];
  }

  $mycate .= "</ul>";
  return $mycategory;
}

And following code used in every php file to display my category

Code: [Select]
$brand = get_mycategory();
if (!$mycategory)  {
  $brand = $lang['no_cate];
}
$site_template->register_vars("mycategory", $mycategory);
unset($mycategory);

My codes workes fine for every parent link
Suppose, www.mysite.com/mycategory.php, www.mysite.com/mytest.php etc.

But shows only Birds (not full category list) like bellow if the link is
www.mysite.com/mycategory.php?mycat=birds

My Category
Birds


Note, mycategory.php used for browsing all this category

How can I solve this? Please help.