Author Topic: How to check if current page is main page or category index or details page ?  (Read 10085 times)

0 Members and 1 Guest are viewing this topic.

Offline adrianTNT

  • Newbie
  • *
  • Posts: 14
    • View Profile
Hello.

I want to change page title so that:
- on main page of gallery title is "{site_name}"
- on category page title is "{site_name} - {cat_name}"
- on photo details page title is "{site_name} - {image_name}"

How can I do that? I see <title> tag is set in header.html so I need to write it there but I have to test if current page is a photo details or home page or a category page, how can I test this?

Thank you.
- Adrian.


Offline adrianTNT

  • Newbie
  • *
  • Posts: 14
    • View Profile
http://www.4homepages.de/forum/index.php?topic=6613.0
Bitte sehr :p
Thanks but... that mod is way too long for such a small modification.
I just need  way to detect if current page is one of these 3:

- main page
- a category
- or a photo details page.

Else page title will just be {site name}.
Any ideas ?

Offline drastx

  • Newbie
  • *
  • Posts: 41
    • View Profile
http://www.4homepages.de/forum/index.php?topic=6613.0
Bitte sehr :p
Thanks but... that mod is way too long for such a small modification.
I just need  way to detect if current page is one of these 3:

- main page
- a category
- or a photo details page.

Else page title will just be {site name}.
Any ideas ?

I think thats the EASIEST and SHORTEST and MOST-LESS-TROUBLE way ;)

Offline adrianTNT

  • Newbie
  • *
  • Posts: 14
    • View Profile
I found a more simple, faster solution, I will write the steps in case someone will want to change its page title.

in top of header.html change the html title tag to:
Code: [Select]
<title>{page_title}</title>


Now we will need to set a default value for that template id, then in each new type of page (photo details, categories, upload page, etc) you will be able to set new page title scheme.
To set a default value for page title open page_header.php and type this at the end of file
Code: [Select]
//-----------------------------------------------------
//--- set a default page title ------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
"page_title" => $config['site_name']
));
Now on all pages on site title will be your site name read from settings unless you specify different for each type of page:

To have a custom title in other page type (categories, details, upload page, etc) you need to give a value to that template variable {page_title} after it says //--- Print Out --. For example: open categories.php and locate //--- Print Out --, add a value for {page_title} there so it looks like this:
Code: [Select]
$site_template->register_vars(array(
  "msg" => $msg,
  "clickstream" => $clickstream,
  "page_title" => 'Photos of '.format_text($cat_cache[$cat_id]['cat_name'], 2)
));
On my site the above will set a title like 'Photos of Porsche', 'Porsche' being the title of current category.


To have the name of the photo in page title when vieving a photo: open details.php and after it says //--- Print Out -- add a value for {page_title} there (last line) so it looks like this:
Code: [Select]
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  "msg" => $msg,
  "clickstream" => $clickstream,
  "lang_category" => $lang['category'],
  "lang_added_by" => $lang['added_by'],
  "lang_description" => $lang['description'],
  "lang_keywords" => $lang['keywords'],
  "lang_date" => $lang['date'],
  "lang_hits" => $lang['hits'],
  "lang_downloads" => $lang['downloads'],
  "lang_rating" => $lang['rating'],
  "lang_votes" => $lang['votes'],
  "lang_author" => $lang['author'],
  "lang_comment" => $lang['comment'],
  "lang_prev_image" => $lang['prev_image'],
  "lang_next_image" => $lang['next_image'],
  "lang_file_size" => $lang['file_size'],
  "page_title" => $image_name
));
That will set image name as page title.

It looks simpler than the other long solution I saw but maybe someone can verify what I wrote, it works very well for my site  :lol:

Offline medo007

  • Newbie
  • *
  • Posts: 29
  • Internet addict
    • View Profile
It looks simple! I'll try it!  :)
mEDO

Offline Falldog

  • Newbie
  • *
  • Posts: 27
    • View Profile
It worked like a charm for me.

Offline MaveriC

  • Newbie
  • *
  • Posts: 32
    • View Profile
excellent tweak .. more of common sense than code!  :lol:

Offline gls

  • Newbie
  • *
  • Posts: 37
    • View Profile
I want to remember to try this.