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.

Help with PHP Conditionals

July 31, 2010 1:16am

Subscribe [2]
  • #1 / Jul 31, 2010 1:16am

    xenowebdev

    34 posts

    Hey guys,

    I’m using a single template to display landing, category, filtered category and detail page.
    All is working well until we get to the pagination. I tried using the ‘MD Detect Page Type’ plug-in but it didn’t work for me.

    I’ve added the PHP Conditional answer from this thread to help solve this:

    http://ellislab.com/forums/viewthread/80605/

    My code is:

    <?php
    global $IN;
    $qstring = $IN->QSTR;
    $seg2 = '{segment_2}';
    
    if ($seg2 == '' OR preg_match("#(^|\/)P(\d+)#", $qstring)) { ?>
    {embed="includes/landing_page"}
    <?php } else { ?>
    {embed="includes/category_page"}
    <?php } ?>
    
    <?php
    global $IN;
    $qstring = $IN->QSTR;
    $seg4 = '{segment_4}';
    if ($seg4 == '' OR preg_match("#(^|\/)P(\d+)#", $qstring)) { ?>
    {embed="includes/filtered_category_page"}
    <?php } else { ?>
    {embed="includes/detail_page"}
    <?php } ?>

    This is the closest I’ve got to making this work. I need to check ‘segment_2’ and ‘segment_4’. Both code segments work as they should individually but I need them to be one conditional statement on the page. Can someone help me do this please?

    Thanks

  • #2 / Jul 31, 2010 2:18am

    xenowebdev

    34 posts

    SOLUTION FOUND:

    Here’s the code that works for this problem.

    {if segment_3 == ""}
    <?php
    global $IN;
    $qstring = $IN->QSTR;
    $seg2 = '{segment_2}';
    
    if ($seg2 != '' OR preg_match("#(^|\/)P(\d+)#", $qstring)) { ?>
    {embed="includes/category_page"}
    <?php } else { ?>
    {embed="includes/landing_page"}
    <?php } ?>
    {/if}
    
    {if segment_3 != ""}
    <?php
    global $IN;
    $qstring = $IN->QSTR;
    $seg4 = '{segment_4}';
    
    if ($seg4 == '' OR preg_match("#(^|\/)P(\d+)#", $qstring)) { ?>
    {embed="includes/filtered_category_page"}
    <?php } else { ?>
    {embed="includes/detail_page"}
    <?php } ?>
    {/if}

    By wrapping the PHP conditionals in EE conditional tags I get what I need. I’m not sure if this is the best way to do this as I’m only new to PHP but it does what I need it to do and I get my pagination working.

    😊

  • #3 / Aug 01, 2010 10:49am

    Greg Salt

    3988 posts

    Hi Steve,

    Glad that you found a solution for this.

    Cheers

    Greg

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

ExpressionEngine News!

#eecms, #events, #releases