Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    35
    Plugin Contributions
    0

    Default cPath IF statements - calling sub cPaths

    Hi All,

    Running into something which I think could be done a bit more efficiently on my part (and will save manual work later on) which I need some help with.

    (Running on Zen 1.3.8 and can't seem to find an example of this on the forums)

    I have an element on a clients site which needs to call the cPath which is active to display:

    <?php $PIC=$_GET["cPath"];
    if ($PIC=="140" or $PIC=="140_95") echo "<li class='current'>";
    else echo "<li>"; // DEFAULT ?>


    Rather than listing out each subcategory (ie 140_96, 140_100, etc.) IS it possible to somehow call subcategories BELOW 140 in the example above so anything in cPath 140 or subcategories below will see <li class='current'>?

    Thinking or $PIC=="140_" or or $PIC=="140*" but naturally these won't work

    Obviously hardcoding will work for now, but thinking if its grabbing it as a * or something it will spare us from updating whenever a new subcategory gets added.

    Any thoughts or advice how to accomplish would be greatly appreciated - thanks everyone!

  2. #2
    Join Date
    Mar 2010
    Location
    UK
    Posts
    445
    Plugin Contributions
    0

    Default Re: cPath IF statements - calling sub cPaths

    Investigate preg_match, as it can use regular expressions, like '/^140_/' or similar.

    The pattern to be checked can also be defined in a variable.

  3. #3
    Join Date
    Nov 2006
    Posts
    35
    Plugin Contributions
    0

    Default Re: cPath IF statements - calling sub cPaths

    Thanks!

    Did some Google searches on preg_match though and yeah I'm really out of my league on this one.

    Does anyone have a possible working example of how to use preg_match in relation to what I'm attempting?

 

 

Similar Threads

  1. Retrieving Sub-Cats cPath
    By rbarbour in forum General Questions
    Replies: 2
    Last Post: 10 Sep 2013, 10:10 PM
  2. Meta statements
    By rdcast in forum General Questions
    Replies: 1
    Last Post: 14 Mar 2010, 07:56 PM
  3. Determining root category ID while in a sub-category [cPath question]
    By stealthify in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 9 May 2009, 03:22 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
  •  
disjunctive-egg