Results 1 to 15 of 15

Thread: if top category equals == 'X' display elseif?

  1. #1
    Join Date
    Jan 2008
    Posts
    141

    Default if top category equals == 'X' display elseif?

    Hello!

    I'm wondering what's the code for parent category? I figured out for subcategories it is category_id but I need the parent category code.

    I'm gonna use it in row.html to display a little icon next to each link. The icon is related to the top category. At the moment I have to add the code to EACH subcategory to make the icon display. It would be easier if I could add it only to the parent category, since then, it would obviously display for all categories.

    I'm using
    Code:
    <%if $category_id =='28'%>
    <%elseif $category_id =='2'%>
    <%elseif $category_id =='3'%>
    <%elseif $category_id =='4'%>
    <%elseif $category_id =='5'%>
    <%elseif $category_id =='6'%>
    <%/if%>
    I tried this, but didn't work:
    Code:
    <%if $parent_category_id =='28'%>
    <%/if%>

  2. #2
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    The "code" for a parent cat is the same as any other category, except that it has a 0 for parentid.

    You should be able to use the variable $parent

  3. #3
    Join Date
    Jan 2008
    Posts
    141

    Default

    Maybe it's not parent id I'm looking for? It definitively didn't work to use just $parent... It's top category and the ID is 28...

  4. #4
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    You're asking about parentid. If you just want the code for matching a category it would be <%if $cat == catnumberhere%>

  5. #5
    Join Date
    Jan 2008
    Posts
    141

    Default

    No you see... My categories looks like this:
    English (id=28)
    --- A (id=2)
    --- B (id=3)
    --- C (id=4)
    --- D (id=5)
    ....and so on
    Norwegian (id=33)
    --- A (id=35)
    --- B (id=36)
    --- C (id=37)
    --- D (id=38)
    ....and so on
    From that example you can see that I need the English and Norwegian cat id, and it only works with the sub categories. In other words, Instead of adding flag to only id 28 or id 33, I have to add to all letters in the alphabet for EACH category.

    Makes better sense?

  6. #6
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    <%if $parent == 33%> should work

    No quotes in there by the way, try it exactly as i typed it.

  7. #7
    Join Date
    Jan 2008
    Posts
    141

    Default

    I'm afraid it didn't work. No image displayed at all. Tried with text, didn't work either.

    Code:
    <%if $parent == 33%><img border="0" src="/themes/kosmos/images/flags/usauk.gif" width="32" height="20">
    <%/if%>

  8. #8
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    The big question now, is where are you placing this and is $parent a valid variable for that page? Check the corresponding .php file for $parent and if it's not there then it wont work. Of course it could be added.

  9. #9
    Join Date
    Jan 2008
    Posts
    141

    Default

    row.html... but I don't find any row.php

  10. #10
    Join Date
    Jun 2002
    Location
    Winnipeg Canada
    Posts
    4,913

    Default

    in browse.php find the following

    // vars url & form
    global $cat, $pg_which;

    Replace with

    // vars url & form
    global $cat, $parent, $pg_which;

    And it SHOULD work

  11. #11
    Join Date
    Jan 2008
    Posts
    141

    Default

    Still doesn't work...
    Code:
        // vars url & form
        global $cat, $parent, $pg_which;

  12. #12
    Join Date
    Jan 2008
    Posts
    141

    Default

    Alright .... since it didn't work anyone know the code for equals from to?
    Instead of
    Code:
    <%if $category_id =='28'%>
    <%elseif $category_id =='2'%>
    <%elseif $category_id =='3'%>
    <%elseif $category_id =='4'%>
    <%elseif $category_id =='5'%>
    <%elseif $category_id =='6'%>
    <%/if%>
    I would just write
    Code:
    <%if $category_id =='2-28'%>
    <%/if%>
    ...or something like that? Is there a formula for that?

  13. #13
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default

    in php its something like

    if ($x >= 100 && $x <= 1000)

    so that would be between 100 and 1000

  14. #14
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    in smarty you could do this

    if $parent => lownumber | $parent <= highnumber

    from memory the " | " (bar) in smarty is OR, check that out ont he smarty site though
    Main IndexU sites : | Campsite Directory | Tourist Guide | Places2B | AfterDirectory <-- Half price submission using coupon DP50 (from just $11 premium, and $10 basic permanent )

  15. #15
    Join Date
    Jan 2008
    Posts
    141

    Default

    Thanks lot's! I used
    Code:
                    <%if ($category_id >= 2 && $category_id <= 30)%><img border="0" src="/themes/kosmos/images/flags/usauk.gif" width="32" height="20">
                    <%elseif ($category_id >= 33 && $category_id <= 65)%><img border="0" src="/themes/kosmos/images/flags/norway.gif" width="32" height="20">
                    <%/if%>
    worked very good

Similar Threads

  1. Sub-Category Display??
    By Scripter1 in forum v5.x
    Replies: 2
    Last Post: 02-25-2008, 05:48 PM
  2. display category
    By Hart_House in forum Tutorials, Hints & Tips
    Replies: 5
    Last Post: 09-17-2007, 02:17 PM
  3. display category name
    By sanjeev in forum v5.x
    Replies: 2
    Last Post: 01-17-2005, 08:48 PM
  4. category display
    By Hart_House in forum v5.x
    Replies: 1
    Last Post: 12-03-2001, 04:57 PM
  5. Replies: 6
    Last Post: 11-21-2001, 06:21 PM

Posting Permissions

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