We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Previous and next button to go to the next active id | Forum

Ken
Ken Nov 2 '20
Put a Previous and next button to go to the next active id on view page

<input style='float:left' type="button" class="prev-btn" name="b1" value="prev" onclick="location.href='/item/view/{$item->id-1}'">
<input style='float:right' type="button" class="next-btn" name="b2" value="next" onclick="location.href='/item/view/{$item->id+1}'">

This works but If next number id missing it will give an error 
How to rewrite this to go to next or previous only active id item...


href='/item/view/{$item->id+1}

Any simple suggestions????
dave Team
dave Nov 28 '20

try wrapping your next button with an if, untested but youll get the idea


something like


{if $item->id+1}

<input style='float:right' type="button" class="next-btn" name="b2" value="next" onclick="location.href='/item/view/{$item->id+1}'">

{/if}


you may have to qualify it but not sure something like


{if $item->id+1 eq whatever}  whatever that value might be, null 0 im not sure what it would be in your case.


in smarty you can use  eq for =   ne for !=   gt  for >   amd   lt for < 

equals notequals greaterthan lessthan



Ken
Ken Dec 6 '20
I used {if count($nextitem) > 0 }
The Forum post is edited by Ken Dec 6 '20