[SOLVED] List of categories for isotope filter in CGBlog

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

[SOLVED] List of categories for isotope filter in CGBlog

Post by carasmo »

Okay, this has stumped me. What I have is a list of blog posts that have different categories assigned to them. Each post can have many categories assigned to it. On the page, I have a filter list to filter by category, so far this code works but it prints every instance, that is if 10 posts are assigned to category A, then it prints it out 10 times. So really how can you have a foreach that only lists it one time, not foreach but only one instance.

Code: Select all

 
<ul>
  <li><a class="active" href="#" data-filter="*">All</a></li>
{foreach from=$items item=entry}
{foreach from=$entry->categories item='one_category'}
{foreach from=$categories item='one'} 
{if $one_category.name == $one.name}
  <li><a href="#" data-filter=".{$one.name|munge_string_to_url}">{$one.name}</a></li>
{/if}
{/foreach}
{/foreach}
{/foreach}
</ul>
Basically this is printed on the same page as the blog summary page and it can't be without the foreach from the item=entry since it's going by what's on that page, not what categories there are. If a post on that page is not assigned to a category, then just using the category navigation won't work. God, it's hard to make sense of this...
Last edited by carasmo on Tue Aug 28, 2012 10:23 pm, edited 2 times in total.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: List of categories for isotope filter in CGBlog

Post by carasmo »

Now it works up to a point. That is it will list out each time, so if a post is using the same category 5 times, it will list it 5 times.
Jean le Chauve

Re: List of categories for isotope filter in CGBlog

Post by Jean le Chauve »

Maybe you could add the $one.name that is already out in an array with the {append} and do a test with {while} instead of {foreach}.

Functions : {append} {while}
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: List of categories for isotope filter in CGBlog

Post by Jos »

How about {CGBlog action='browsecat'} and then create your own Browse Category Template?
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: List of categories for isotope filter in CGBlog

Post by carasmo »

@Jos,

Tried that, but that prints out all categories. What I'm trying to do is this:

http://spab-rice.com/wordpress/rawa/

Notice the filters. When you go to the next page, it builds them by those on the page, not what categories you have. I've gotten so far, but I can't get this part to work. If I could just get the foreach to be one time per matching string, then it would rock.

Code: Select all

<ul>
<li><a class="active" href="#" data-filter="*">All</a></li>
{foreach from=$items item=entry}{foreach from=$entry->categories item='one_category'}{if $one_category.name == $one.name}{foreach from=$categories item='one'}
<li><a href="#" data-filter=".{$one.name|munge_string_to_url}">{$one.name}</a></li>
{/foreach}{/if}{/foreach}{/foreach}
</ul>
This creates a filter list, but it prints out a strange number, if there are 2 posts assigned to category one, it prints it out three times and on the following pages it prints out nothing.
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: List of categories for isotope filter in CGBlog

Post by manuel »

Hi Carasmo,

Below, you will find what i did once for CGBlog (creating a custom category list and calling that).
You should easily be able to convert this to use for the News module but i suppose it will require some more work to get it to achieve the exact result you want...

I'm posting this to hopefully point you in the right direction, not to fix the issue with a copy/paste ;)
If i'm completely off topic, at least i tried! ;D

I'll try to provide you with the juicy bits here:

PART 1: Get the required info:
(Call & trash CGBlog to get category information (cfr. PART 2) before calling CGBlog with final list)

Code: Select all

{capture assign="junk"}{CGBlog}{/capture}
PART 2: Create the array containing the categories

Code: Select all

{foreach from=$items item=entry}
	{foreach from=$entry->categories item='category'}
		{if isset($newscats) && $category.name|in_array:$newscats}
			{*Do nothing because newscats array exists and contains the category*}
		{else}


{* HERE YOU CAN DEFINE MULTIPLE CONDITIONS THAT WOULD HAVE TO BE MET BEFORE ALLOWING THE CATEGORY TO BE INCLUDED IN THE FINAL LIST - LET ME KNOW IF YOU WANT TO SEE WHAT I PUT HERE AS AN EXAMPLE *}


			{capture append='newscats'}{$category.name}{/capture}



		{/if}
	{/foreach}
{/foreach}
PART 3: Convert the newscats array to finalnewscats string while making the string comma separated

Code: Select all

{capture assign="finalnewscats"}
	{foreach from=$newscats item=qsdf name=foo}
		{$qsdf}{if $smarty.foreach.foo.last != '1'},{/if}
	{/foreach}
{/capture}
Part 4: Call CGBlog using the custom built category string

Code: Select all

{if isset($finalnewscats)}
	{CGBlog lang="nl_NL" category="$finalnewscats" detailpage="nieuws" sortasc="false"}
{/if}
Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: List of categories for isotope filter in CGBlog

Post by carasmo »

Thank you so much for taking the time to write this. It will be helpful for another purpose, but I think I've figure out another route, which is jquery to build the navigation, since the filter only works with jquery, the navigation being built by it will not be an issue.
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: List of categories for isotope filter in CGBlog

Post by manuel »

You welcome, i was afraid it was a bit off topic...

ps: something similar to Isotope http://razorjack.net/quicksand/

Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: List of categories for isotope filter in CGBlog

Post by carasmo »

http://stackoverflow.com/questions/1206 ... es#tab-top

Some awesome being helped me!!! Much love!

Code: Select all

<ul>
    <li><a class="active" href="#" data-filter="*">All</a></li>
    {assign var="tempCat" value=""}
    {foreach from=$items item=entry}
        {if $entry->categories} 
        {strip}
            {foreach from=$entry->categories item='category'}
                {if !$tempCat|strstr:$category.name} 
                    <li><a href="#" data-filter=".{$category.name|munge_string_to_url}">{$category.name}</a></li>
                    {assign var="tempCat" value=$tempCat|cat:$category.name}
                {/if}
            {/foreach}
        {/strip}
        {/if}
    {/foreach}
</ul>
Post Reply

Return to “The Lounge”