ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to hide code unless on a category page?

May 20, 2010 3:50pm

Subscribe [4]
  • #1 / May 20, 2010 3:50pm

    flojnel

    17 posts

    I’m using Structure so this may be a Structure question, but thought I’d try general support first. I have a directory page that shows a categories menu for various geographic locations. Each category contains a list of people with their website, phone, etc. The list is in a table.

    Everything works fine on all the category pages, but on the directory landing page, I can’t figure out how not to show the table headings. I’ve tried a lot of different {if}, {if:else} combinations but nothing’s working. I’m new to EE and a novice with php. Here’s the code I’m using:

    {exp:weblog:categories weblog="directory" dynamic="off"}
                <a href="?category={category_id}">{category_name}<a>
    {/exp:weblog:categories}
    
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <th scope="col" valign="top">Name</th>
                      <th scope="col" valign="top">Website</th>
                      <th scope="col" width="20%" valign="top">Phone</th>
                      <th scope="col" valign="top">Area Served</th>
                      <th scope="col" valign="top">Specialty</th>
                    </tr>
            {exp:weblog:entries weblog="directory" category="<?php echo $_GET['category']; ?>" dynamic="off"}
                    <tr class="{switch="alt|even"}">
                      <td valign="top">{first_name} {last_name}</td>
                      <td valign="top">{website}</td>
                      <td valign="top">{phone}</td>
                      <td valign="top">{area}</td>
                      <td valign="top">{specialty}</td>
                    </tr>
            {/exp:weblog:entries}
            </table>

    Any ideas?
    Flo

  • #2 / May 20, 2010 4:19pm

    Ingmar

    29245 posts

    Have you seen the {if category_request} conditional? Might be what you’re looking for.

  • #3 / May 20, 2010 4:48pm

    flojnel

    17 posts

    Thanks, but that doesn’t work either - wrapped it around the start of the table code - then it’s hidden on the landing page, but also on the categories pages.

  • #4 / May 20, 2010 7:08pm

    Brandon Jones

    5500 posts

    Could you get away with looking at the URLs and using segment variables with a conditional to determine if you’re on the landing page? We may need to shift this over to How-to.

  • #5 / May 20, 2010 8:55pm

    flojnel

    17 posts

    Brandon, you’re right - I should have been posting in “how to.”

    I have tried working with segments. Added a plugin that can detect if a string is in one of the segments of the url - thought that would work, but it didn’t (at least not the way I did it).

  • #6 / May 21, 2010 1:31am

    John Henry Donovan

    12339 posts

    flojnel,

    What is the url of your directory landing page?

    I am going to move this to the How to forum for you as more appropriate there as Brandon says.

  • #7 / May 21, 2010 2:29am

    flojnel

    17 posts

    http://homeovista.ehclients.com/homeopathy_clinic/directory/

    Using the in_segments plugin, I checked a simple statement. The plugin seems to be working because a check for “directory” with an if statement produced the result I expected on the directory landing page. But a check for “category” on a category page didn’t work,even though they end with something like “directory/?category=4”.

    I don’t know how to test to see if we’re on a category page. Being able to do that would solve the problem.

    Flo

  • #8 / May 21, 2010 2:40am

    John Henry Donovan

    12339 posts

    Flo,

    If you wanted a conditional to check if you were on that URL specifically. I would do this.

    {if (segment_2 == "directory") AND (segment_3 == "")}
    Do something
    {/if}

    But a check for “category” on a category page didn’t work,even though they end with something like “directory/?category=4”.

    That doesn’t look like a typical EE URL so I can’t help you there I’m afraid. An EE category URL would look like this

    http://homeovista.ehclients.com/index.php/homeopathy_clinic/directory/C13/

    or if you have named categories set

    http://homeovista.ehclients.com/index.php/homeopathy_clinic/directory/category/category_name

  • #9 / May 21, 2010 1:36pm

    flojnel

    17 posts

    I figured out some php that will give me a class of show or hide depending on whether or not there’s an argument after the “directory” segment.

    <?php
    function setClass() {
     $setClass = '';
     if ($_SERVER['QUERY_STRING']==''){$setClass = "hide";}
    else
    {$setClass = "show";}
    return $setClass;
    }
    
    echo "class=".setClass();
    ?></code></pre>
    
    It's working in a test on the page to give the right class. However, I'm not sure how to integrate it with the following ee code:<pre><code><table border="0" cellspacing="0" cellpadding="0">

    I want to give the table the class.

    I’ve seen code where small snippets of php are integrated into the ee code, but how do you integrate an entire function?

  • #10 / May 21, 2010 2:01pm

    flojnel

    17 posts

    OK - got it working. I didn’t realize I could still use the php variable right in the ee code. Very slick.

    Thanks for all the help everyone. There’s a lot to figure out when you’re doing this for the first time and it’s great to know you have someplace to go to get ideas and support.

    Flo

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases