Page 1 of 1

category template design question

Posted: Mon Sep 07, 2009 2:09 am
by meredeth
i'm helping my sister set up a site, (http://www.jewelry-ninja.com) and all of her posts are actually images and descriptions of items for sale. what we're hoping to do is get a custom category template written that would display her items in a grid, something like this:

Code: Select all

--------------------------
|                               |
|      item           item      |
|                               |
|      item           item      |
|                               |
|      item           item      |
|                               |
|      item           item      |
|                               |
|      item           item      |
|                               |
--------------------------
my question is, basically, is this possible? i was thinking of using a table to display the entries, but i'm not sure how to get smary/s9y to realize that i don't want it to just print the same entry over and over. i looked through the technical documentation on the main site, but i didn't see anything that looked appropriate to this situation. i was thinking i could do something like:

Code: Select all

{foreach dategroup/etc}
<table><tr><td>{$entry.body}</td></tr></table>
but that'll only work for two entries, becase we only need more table rows every other entry. i guess what i'm looking for is some way to tell s9y to +1 entry every time i call the entry.body... or maybe a way to change what's done depending on whether it's an even or an odd-numbered entry? something like:

Code: Select all

{foreach}
<table>
{if entry.even# (i don't know what that variable would look like)}
<tr><td>{entry.body}</td>
{if entry.odd#}
<td>{entry.body}</td></tr>
{/if}
</table>
??? i'm not sure if there's something like this available.

thanks for any assistance!
~meredeth.

Re: category template design question

Posted: Mon Sep 07, 2009 3:04 pm
by garvinhicking
Hi!

Generally, yes, this would work. Additionally to the approach you aim for, creating a custom event plugin would also work well, depending on your skill set. The plugin serendipity_event_customarchive could be a good starting point.

For your immediate question, what you need would be to utilize the smarty {counter} function that you can look up in its documentation. You can create a counter token; or the other way is to give a name to your foreach loop:

Code: Select all

{foreach item=entry from=$dategroup name=myname}
{if $smarty.foreach.myname.index is even}
...
{else}
...
{/if}
{/foreach}
HTH,
Garvin

Re: category template design question

Posted: Tue Sep 08, 2009 1:38 am
by meredeth
ah! i think that counter function is just what i was looking for! (^_^) maybe one day i'll have the skill set for a whole plugin. (^^;)

thanks muchly,
~meredeth.

Re: category template design question

Posted: Sun Sep 13, 2009 3:54 am
by meredeth
ok, well, i think i've got a handle on how to use the counter function, but i apparently do not have a handle on where to use it. should i be creating a seperate page? (called what? categories.tpl maybe? and how would i call it?) or should i be putting this in the entries.tpl? i tried that second option, using the if $entry.categories tag, but i don't think that does what i think it does (namely, i thought that was saying, "if this is a categories page do such and such, but in my trials, the code i put in was executed on both my front page and my categories page, so. after a little more exploration, i think what this actually does is store which categories the particular post is assigned to?).

much appreciated~
~meredeth.

Re: category template design question

Posted: Mon Sep 14, 2009 10:02 am
by garvinhicking
Hi!

You can for example rely on the $view variable inside the entries.tpl file; the view you need is "category", so you can use:

Code: Select all

{if $view == 'category'}
... do this...
{else}
... do the usual stuff ...
{/if}
Regards,
Garvin

Re: category template design question

Posted: Mon Sep 21, 2009 2:43 am
by meredeth
ah! lovely!
$view == 'categories' for the win~

thank you very much, sir.
~meredeth.

Re: category template design question

Posted: Tue Sep 22, 2009 3:30 am
by meredeth
ok, i swear, one day i'll stop asking questions about this. (^^;)

i've got it set up, and it's almost working perfect. turns out my sister wanted that grid view for her top page too, so that was actually easier than i had imagined, but now we're getting odd next/previous button placement. the first page works great, but subsequent pages will have two and three next/prev buttons after different numbers of photos. it's a little hard to explain, but check out page three ( http://jewelry-ninja.com/index.php?/archives/P3.html ) for example. the code is below. i thought maybe the location of the hookPlugins had something to do with it, but moving them didn't seem to have any effect.

thanks~

Code: Select all

<!-- ENTRIES START -->
{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}
 {foreach from=$entries item="dategroup"}

{if not $is_single_entry}
 {counter assign="entryID"}
 <table class="category">
  {foreach from=$dategroup.entries item=entry}
   {if $entryID is odd}
    <tr>
     <td align="center" class="catentry"><h4><a href="{$entry.link}">{$entry.title}</a></h4>
      {$entry.body}
      {counter assign="entryID"}
     </td>
    {elseif $entryID is even}
     <td align="center" class="catentry"><h4><a href="{$entry.link}">{$entry.title}</a></h4>
      {$entry.body}
      {counter assign="entryID"}
     </td>
    </tr>
   {/if}
  {foreachelse}
   {if not $plugin_clean_page}
    <tr><td>{$CONST.NO_ENTRIES_TO_PRINT}</td></tr>
   {/if}
  {/foreach}
 </table>
 <div class='serendipity_entryFooter' style="text-align: center">
  {if $footer_prev_page}
   <a href="{$footer_prev_page}">« {$CONST.PREVIOUS_PAGE}</a>  
  {/if}
  {if $footer_info}
   ({$footer_info})
  {/if}
  {if $footer_next_page}
   <a href="{$footer_next_page}">» {$CONST.NEXT_PAGE}</a>
  {/if}
 </div>
{elseif $is_single_entry}
<!-- pretty much the regular single entry page -->
{/if}
{/foreach}
{serendipity_hookPlugin hook="entries_footer"}
<!-- ENTRIES END -->