Multiple category results in one page

Multiple category results in one page

Postby G. Noel Gross on Thu Mar 20, 2008 9:22 pm

I'd like to create a static template that will display multiple category topics and headlines of my choosing.

Example:

Category A
- Title 1
- Title 2

Category B
- Title 1
- Title 2

Category C
- Title 1
- Title 2

It appears categories are assigned numbers. Is there a way to use these rather than "getName"? It would seem I need to create my template file base on this code ...

Code: Select all
      {assign var="OnMainPage" value=1}
      {include file="$blogtemplate/header.template"}
      
{if $category}<h2>{$locale->tr("")}{$category->getName()}</h2>{/if}
 
{foreach from=$posts item=post}
{if $showAll | 1 && $category}
  <!-- showing only the topic of the post, in case we have too many! -->
<h3>- <a href="{$url->postPermalink($post)}">{$post->getTopic()}</a></h3>


{else}
  <!-- show the whole post, as we would normally do -->
   {include file="$blogtemplate/post.template"}
{/if}
{/foreach}
      
      {include file="$blogtemplate/footer.template"}
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby jondaley on Fri Mar 21, 2008 11:51 am

You probably want to start with this code instead:
Code: Select all
       {foreach from=$articlecategories item=panel_articleCategory}
         <li><a href="{$url->categoryLink($panel_articleCategory)}">
                                {$panel_articleCategory->getName()}</a>
                   [{$panel_articleCategory->getNumArticles()} posts]
           [<a href="{$url->categoryRssLink($panel_articleCategory)}">rss</a>]
         </li>
       {/foreach}


The easiest way is probably to put an
Code: Select all
{if $panel_articleCategory->getName() == "Special Cat"} print stuff {/if}
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Multiple category results in one page

Postby G. Noel Gross on Sun Mar 23, 2008 2:06 am

I'm sorry. I don't follow. :(
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby jondaley on Sun Mar 23, 2008 8:52 am

Code: Select all
{foreach from=$articlecategories item=panel_articleCategory}
  {if $panel_articleCategory->getName() == "Special Cat"}
    <a href="{$url->categoryLink($panel_articleCategory)}">
      {$panel_articleCategory->getName()}</a>
  {/if}
{/foreach}


Did you try pasting the code into a template file? Then modify the "special cat" to whatever category you want to display.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Multiple category results in one page

Postby G. Noel Gross on Sun Mar 23, 2008 12:48 pm

{foreach from=$articlecategories item=panel_articleCategory}
{if $panel_articleCategory->getName() == "W"}
<a href="{$url->categoryLink($panel_articleCategory)}">
{$panel_articleCategory->getName()}</a>
{/if}
{/foreach}

Oh! OK. This is warm. But it only produces a "W (a.k.a. Special Category)" hyperlink ... I was looking for a topics result like so ...

W
- Wasabi
- Wasp Woman
- Watermelon's Baked & Baking
- Weasels Rip My Flesh
- Weird Science
- Where the Buffalo Roam
- Wild Things 2
- Willard
- William S. Burroughs: Commissioner of Sewers
- William Shatner's Spplat Attack
- Witchbabe: The Erotic Witch Project III
- Witches of Breastwick
- The Wizard of Gore
- Womb Raider
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby jondaley on Mon Mar 24, 2008 1:00 pm

Ah, then you'll just want a function to look at the first letter.

Look at smarty.php.net for the allowed functions.

I might use the "truncate" operator on getName() and then compare it to "W". I don't think there is a strncmp function in smarty.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Multiple category results in one page

Postby G. Noel Gross on Mon Mar 24, 2008 3:59 pm

jondaley wrote:Ah, then you'll just want a function to look at the first letter.


Aren't we making this harder than it is?

I just want the results of multiple category queries (sample URLs below) to appear on a single page.

A
- AVP: Alien vs. Predator

T
- They Live

Y
- Year of the Yahoo!
- The Young Nurses

http://cineschlocker.com/index.php?op=D ... 8&blogId=1
http://cineschlocker.com/index.php?op=D ... 9&blogId=1
http://cineschlocker.com/index.php?op=D ... 4&blogId=1
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby G. Noel Gross on Mon Mar 24, 2008 9:52 pm

Seems like this should work. :(

Code: Select all
{if $category}<h2>{$locale->tr("")}{$category->getName() == "W"}</h2>{/if}
 
{foreach from=$posts item=post}
{if $category}<h3>- <a href="{$url->postPermalink($post)}">{$post->getTopic()}</a></h3>{/if}
{/foreach}
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby jondaley on Tue Mar 25, 2008 10:47 am

Oh, I hadn't realized that your categories were named, "A", "B", etc. I thought you wanted to show the categories organized by letter, rather than the posts. Sorry - yes your way is fine.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Multiple category results in one page

Postby G. Noel Gross on Tue Mar 25, 2008 11:11 am

jondaley wrote:Oh, I hadn't realized that your categories were named, "A", "B", etc.

Can you see why my code is busted? I can't seem to get the posts titles to show up.
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby jondaley on Tue Mar 25, 2008 1:47 pm

What do you see as the output?
I'd move the {if category} outside of the foreach loop, but that's just a performance thing, rather than functional.

Also, the $posts object isn't available on every page, I think, just the main pages? What URL are you accessing?

Lastly, you should probably not use $post in your foreach loop, but make up your own variable, otherwise, you overwrite LifeType's $post variable. That would cause your code to work, but if your code is in the header, it will break the main body of your pages.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Multiple category results in one page

Postby martopiggus on Tue Oct 28, 2008 9:42 am

I made a search and found this thread...

I think you have already done it, but I would just post my solution here, I am currently using it in my FAQ website.

One thing to remember, you need to change the number of articles showing on the front page to be greater than the number of total articles.

Code: Select all
{include file="$blogtemplate/header.template"}
{include file="$blogtemplate/sidebar-l.template"}

{assign var=categoryNamePrinted value=0}
{foreach from=$articlecategories item=articleCategory}
      {foreach from=$posts item=post}
           {assign var=thisCategoryId value=$articleCategory->getId()}
           {assign var=postIds value=$post->getCategoryIds()}
           {foreach from=$postIds item=postId}
              {if $postId eq $thisCategoryId}
               {if $categoryNamePrinted eq 0}
                <h3><a href="{$url->categoryLink($articleCategory)}">{$articleCategory->getName()}</a></h3>
                 {assign var=categoryNamePrinted value=1}
                 <ul>
               {/if}
            <li><a href="{$url->postlink($post)}">{$post->getTopic()}</a>
            {assign var="updateDate" value=$post->getModificationTimestamp()}
            {assign var="postDate" value=$post->getDateObject()}
            {assign var="updateDateUnix" value=$updateDate->getUnixDate()}
            {assign var="postDateUnix" value=$postDate->getUnixDate()}
            {assign var="timeDiffUpdateDate" value=$smarty.now-$updateDateUnix}
            {assign var="timeDiffPostDate" value=$smarty.now-$postDateUnix}
            {if $timeDiffPostDate < 604800}
               <span class="new">{$locale->tr("new")}!</span>
            {elseif $timeDiffUpdateDate < 604800}
               <span class="updated">{$locale->tr("updated")}!</span>
            {/if}
            {if $category}
               <p class="preview">{$post->getText()|strip_tags|truncate:300:"...":false}</p>
            {/if}
          </li>
            {/if}
            {/foreach}
      {/foreach}
      </ul>
      {assign var=categoryNamePrinted value=0}
{/foreach} 

{include file="$blogtemplate/footer.template"}


Some extra stuff, if the article is less than 7 days old or being updated within 7 days, a "new" or "updated" tag will be shown beside the article title.

Hope this helps.
Last edited by martopiggus on Sat Nov 15, 2008 3:30 am, edited 1 time in total.
martopiggus
 
Posts: 49
Joined: Wed Jun 22, 2005 1:43 am
Location: Hong Kong

Re: Multiple category results in one page

Postby G. Noel Gross on Mon Nov 10, 2008 3:08 pm

Thanks, martopiggus!

I tried the code and it produced a long string of "Ê"s.

Just pasted it raw into a blank template. Am I missing something?
G. Noel Gross
 
Posts: 31
Joined: Sat Feb 24, 2007 2:33 am

Re: Multiple category results in one page

Postby martopiggus on Sat Nov 15, 2008 3:29 am

You need to put that in the main.template.

I have edited my previous message so it is the complete main.template in my website. I think it can be used in other templates.
martopiggus
 
Posts: 49
Joined: Wed Jun 22, 2005 1:43 am
Location: Hong Kong


Return to Templates

cron