How to display two categories in a single row instead of single column?

Discussion in 'PHP' started by geekology, Jan 4, 2009.

  1. #1
    Hi Everyone,

    This question has to do with both PHP and HTML so I am posting it in PHP forum. I was able to install PHPLD V2, modify and do some minor changes in no time just by going thro' the docs.

    I am stuck up at the template design part, however. Here is the link to my PHPLD directory.

    As you can see there are two main categories Internet and Software that are displayed in a single column. I want these categories to be displayed in a single row (and two columns) instead. I went inside main.tpl file under templates and located this code which I believe is controlling the table behaviour:


    <table border="0" cellpadding="0" cellspacing="30">
          <tr>
             {foreach from=$categs item=cat name=categs}
             {if ($smarty.foreach.categs.iteration mod $cats_per_col eq 1 and $cats_per_col gt 1) or $smarty.foreach.categs.first}<td>{/if}
             <h2><a href="{if $smarty.const.ENABLE_REWRITE}{$cat.TITLE_URL|escape}/{else}index.php?c={$cat.ID}{/if}">{$cat.TITLE|escape}</a>{if $smarty.const.CATS_COUNT} <span class="count">({$cat.COUNT})</span>{/if}</h2>
    
             {* Display subcategories *}
             {if !empty($cat.SUBCATS)}
             <p class="subcats">
                {foreach from=$cat.SUBCATS item=scat name=scategs}
                   <a href="{if $smarty.const.ENABLE_REWRITE}{$cat.TITLE_URL|escape}/{$scat.TITLE_URL|escape}/{else}index.php?c={$scat.ID}{/if}">
                {$scat.TITLE|escape}</a> {/foreach}
             </p>
             {/if}
             {if ($smarty.foreach.categs.iteration mod $cats_per_col eq 0 and $cats_per_col gt 1) or $smarty.foreach.categs.last}</td>{/if}
             {/foreach}
          </tr>
          </table>  
    PHP:
    I did a lot of hit-and-try but was not able to reach at my desired solution. Probably I am missing something there...

    Can someone please help? Let me know if you need more info.

    Thanks!
     
    geekology, Jan 4, 2009 IP
  2. Valdor

    Valdor Well-Known Member

    Messages:
    450
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    185
    #2
    I downloaded the script so will have a look.
    Did you mess with line
    
    $smarty.foreach.categs.iteration mod $cats_per_col eq 1 and $cats_per_col gt 1
    
    Code (markup):
    to see what happens
     
    Valdor, Jan 4, 2009 IP
  3. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Yes I did. I removed
    $smarty.foreach.categs.iteration mod $cats_per_col eq 1 and
    PHP:
    but to no avail.
     
    geekology, Jan 4, 2009 IP
  4. Valdor

    Valdor Well-Known Member

    Messages:
    450
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    185
    #4
    i added a <td> after this line
    
    {foreach from=$categs item=cat name=categs}
    
    Code (markup):
    to make
    
    <table border="0" cellpadding="0" cellspacing="30">
          <tr>
             {foreach from=$categs item=cat name=categs}
    <td>
             {if ($smarty.foreach.categs.iteration mod $cats_per_col eq 1 and $cats_per_col gt 1) or $smarty.foreach.categs.first}<td>{/if}
             <h2><a href="{if $smarty.const.ENABLE_REWRITE}{$cat.TITLE_URL|escape}/{else}index.php?c={$cat.ID}{/if}">{$cat.TITLE|escape}</a>{if $smarty.const.CATS_COUNT} <span class="count">({$cat.COUNT})</span>{/if}</h2>
    
    
    Code (markup):
    but this puts them all on one line
     
    Valdor, Jan 4, 2009 IP
    geekology likes this.
  5. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #5
    That did it. i won't have too many categories so this is fine for me...

    I wonder , How come I didn't think this :eek:

    Anyways, Thanks Valdor. +repped
     
    geekology, Jan 4, 2009 IP