Results 1 to 5 of 5

Thread: Name of the parnet category

  1. #1
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default Name of the parnet category

    i would like to get the name of the main category (parent) on the details page. I mean on detail page I have structure CAT1->SUBCAT1->SUBCAT2 I would like to get "CAT1" name only.

    Is this possible to get that ? and howto ?

    edit:

    $category_name gives me only the last SUBCAT

  2. #2
    Join Date
    Aug 2008
    Location
    Paris, France
    Posts
    46

    Smile A possible solution ?

    Hi Linksor,

    Parent category is, I guess, $parent, but you cannot access it on the detail page.

    You can access $category_path and then write a few lines of PhP code in order to truncate it.

    It should probably read like this :

    <?php

    /* transferring category path from Smarty (I guess) to Php */
    $category_path = $this->get_template_vars('category_path');


    /* extraction of parent category */
    $gt_position = strpos($category_path,'>')-1;
    $parent_label = substr($category_path,0,$gt_position);

    /* transferring parent category to Smarty */
    $this->_tpl_vars['parent_label'] = $parent_label;

    ?>

    Now, you can use <%$parent_label%> in detail_link.html

    (Have no time to test this, but works probably. It is possible it will truncate one character less or more than necessary, just change "- 1" in the formula for $gt_position).

    Hope it will help
    Gus

  3. #3
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default

    works.

    but now I see the problem I have banner at the header (file header.html).

    So is there any chance to make it operational in all templates ?

  4. #4
    Join Date
    Aug 2008
    Location
    Paris, France
    Posts
    46

    Default I am not sure I understand

    What do you exactly mean ?
    Can you be more precise ?

    Maybe this is the answer you are looking for ?
    You can put this code anywhere you want in the <head> or in the <body> section (but not split it into two parts, one for head, the other one for body ).
    If you got the same header.html for your various templates, you can put the code in it. More precisely, you will have to create a headerdetail.html for your detail pages : it will be a copy of header.html that will also contain this code. Then you will have to write <%include file="headerdetail.html" ... instead of header.html in the detail pages.

    If you meant something else, please explain a little more.

    Gus

  5. #5
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default

    Thanx for your help - you gave me a signal to do a little think

    I have used the following code:

    All modification in detail.php

    1. make a variable $parent_name available globally and add it to the template

    Code:
       // vars template
        global $link_detail, $pagination, $review_rows, $ofc_review, $page_title,
                 $link_id, $link_title, $link_description, $link_keywords,
                 $category_id, $category_name, $category_path, $category_path_with_link, $parent_name,
                 $num_review, $avg_review, $avg_review_image;
    Code:
        DisplayTemplate($theme_path . "detail.html",
                        "\$page_title,\$link_id,\$link_title,\$link_description,".
                        "\$link_keywords,\$link_detail,\$avg_review,\$num_review,".
                        "\$avg_review_image,\$review_rows,\$ofc_review,\$pagination,".
                        "\$category_id,\$category_name,\$category_path,\$parent_name,".
                        "\$category_path_with_link");

    2. Add following code before DisplayTemplate

    Code:
    		// name of the parent category
    		$query_parent = "select name from idx_category where category_id = (select parent_id from idx_category where category_id = '$category_id')";
    		$row_parent = $dbConn->FetchOne($query_parent);
    		$parent_name = $row_parent['name'];
    And $parent_name is available in detail.html

Similar Threads

  1. create a category in the menu but link to another category?
    By mxwebsites in forum Blocks and Modification
    Replies: 6
    Last Post: 06-23-2009, 12:03 AM
  2. randomly retriving a category from <%$category%>
    By echo@ in forum Blocks and Modification
    Replies: 13
    Last Post: 03-26-2008, 11:21 PM
  3. Replies: 2
    Last Post: 01-02-2008, 07:25 AM
  4. Replies: 6
    Last Post: 06-02-2005, 09:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •