ListIt2 next and previous items breaks when > 5 items

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

reference: viewtopic.php?f=28&t=74659

ListIt2 1.4.1
CMSMS 1.12.1

I know this is an unsupported version so please bare with me.

I applied the code form the above post and it has been working perfectly for over a year, My client decided to add more items to the list and now it is not working correctly.

The issue only arrises when 6 or more items are available. 5 item works as expected.

The code below is what resides in the detail page

Code: Select all

{$current_id = $item->item_id}

{ListIt2CaseStudies summarytemplate=next_prev assign=dummy}

{foreach $items as $sumitem}

  {if $sumitem->item_id == $current_id}

  	{$iteration=$sumitem@iteration}

    {if $iteration > 1}
    	{$prev_link = $items[$iteration-1]->url}
    {/if}

	{if $iteration < $sumitem@total}
		{$next_link = $items[$iteration+1]->url}
	{/if}

  {break}

  {/if}

{/foreach}

{*Links*}

{if isset($prev_link)}<a class="btn btn-left" href="{$prev_link}">prev</a>{/if}

{if isset($next_link)}<a class="btn btn-right" href="{$next_link}">next</a>{/if}

The summary template 'next_prev' is empty as instructed in the post above.

any help would be very welcome

Thanks

Mark
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

I don't think the count of items (within reasonable limits) will influence this functionality.

I'd expect something else has changed too.

I'd add a line to debug to see what is returned by the {listit2CaseStudies..} call

Code: Select all

...
{ListIt2CaseStudies summarytemplate=next_prev assign=dummy}
<pre>{$items|print_r}</pre>
...
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

Hi @velden

The debug shows that the position and item_id do not corrolate.

i.e

Code: Select all

item_id    position
1             0
2             1
6             2
3             3
4             4
5             5
The end user has changed the order, could this be the issue as the items are no longer sequential by item_id?

thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

The end user has changed the order, could this be the issue as the items are no longer sequential by item_id?
I don't think so because the code uses the array index to get the next and previous items. So it should work.

BTW: you don't describe what does happen when things go wrong.
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

Hi @velden

I have just changed the sort order to as per the item_id sequence 123456.

this seems to now work but not in the desired sequence.

I tried using the position integer to calculate the prev next sequence but unfortunately, because 0 is not a valid integer for calculating the function doesn't work all together.

thoughts welcome on this one.

thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

Position is not relevant for this function.

It iterates the array. The items in the array should be in order defined by position, and they are as shown by your previous post.

During iteration it checks if the currently displayed item's id = item id in the array. If so, it will take the url of the previous item (from the array) and the next item (if the array).

Add some debug lines to see what does happen.
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

The script is using the item_id as its index so that the math counts + or - on the item_id integer.

the sequence of the items is defined by the position, the actual sequence that is presented is 1,2,3,4,5 and misses 6 completely, it the gets stuck on 5 as 6 is still available but not in the sequence the script is expecting.

as I commented, changing the position to be 123456 for item_id and 012345 for position the script work perfectly as expected and only when the position is altered does it break the script.

I am at a loss as the debug doesn't give me anything valuable other than the computed sequence.

Thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

The script is using the item_id as its index so that the math counts + or - on the item_id integer.
I don't see it. It's using the iteration 'value'. It just uses the item_id to match the currently displayed item from the array.
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

I have added the link to the staging server here http://iaw.trstaging.co.uk/case-studies ... omorrow/21
so you can see the sequence and the debug dump.

not sure I am explaining properly the sequence jumps when not in numerical sequence by item_id, regardless of how the 'value' is generated by @iteration. it may be a smarty issue that @iteration can't handle the sequence. I don't actually know!

thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

Yes, I see the problem now. Sorry. Didn't realize the array's keys were the item_id values. Let me think.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

Try this please (untested so please backup current code first!)

Code: Select all

{$current_id = $item->item_id}
{$found = $false}

{ListIt2CaseStudies summarytemplate=next_prev assign=dummy}

{foreach $items as $sumitem}
  {if $found} 
     {$next_link = $sumitem->url}
     {break}
  {/if} 

  {if $sumitem->item_id == $current_id}
    {if !$sumitem@first}{$prev_link = $tmp_prev_link}{/if}
	{$found = true}
  {/if}

  {$tmp_prev_link = $sumitem->url}
{/foreach}

{*Links*}

{if isset($prev_link)}<a class="btn btn-left" href="{$prev_link}">prev</a>{/if}
{if isset($next_link)}<a class="btn btn-right" href="{$next_link}">next</a>{/if}
Note this code will not work in later versions of CMSMS because of variable scopes.
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

That works, although the prev button is no longer visible

thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: ListIt2 next and previous items breaks when > 5 items

Post by velden »

Yeah, remove one '=' sign from the code (edited previous post):

Code: Select all

{if !$sumitem@first}{$prev_link = $tmp_prev_link}{/if}
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Re: ListIt2 next and previous items breaks when > 5 items

Post by blackrain »

BOOM!!! you da man!

top work sir, that works perfectly :)

Thanks so very much

Mark
Post Reply

Return to “The Lounge”