#1 2016-02-17 13:18:31

larzeni
Member
Registered: 2015-08-21
Posts: 24

Allowing user to change articles sort order

Hi there,
I have a simple page that shows all articles sorted by date.

<ion:articles order_by="date DESC">
    <ion:article>
          //do something
    </ion:article>
</ion:articles>

I would like to allow users to change the sort ordering, and show articles sorted by dates ascending.
I placed a form into the page, so that the user can select the sort ordering (ASC or DESC) and post it into the page.

When I receive the POST, I can read it with PHP  and store it into a var (let's call it $sortOrder), but I cannot pass it into the page, that is, I cannot do something like:

<ion:articles order_by="date <?php echo $sortOrder; ?>">
    <ion:article>
          //do something
    </ion:article>
</ion:articles>

This is obvious since php get's evaluated after the ionize tags.

So, what is the "ionize way" to allow a user to sort articles?

Thanks, larzeni

Offline

#2 2016-02-17 22:51:03

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: Allowing user to change articles sort order

Hi,

Quick dirty method is to do an if statement above the ionize tags:

<?php if($sortOrder == "DESC"): ?>
<ion:articles order_by="date DESC">
    <ion:article>
          //do something
    </ion:article>
</ion:articles>
<?php endif; ?>

<?php if($sortOrder == "ASC"): ?>
<ion:articles order_by="date ASC">
    <ion:article>
          //do something
    </ion:article>
</ion:articles>
<?php endif; ?>

Other methods(could get more complicated if pagination is involved):
Use JavaScript - on click of button you could have JS re-order for you since the data is already on the page
Modify ...\application\libraries\Tagmanager\Article.php to handle this
Ajax - method that outputs article data in ASC or DESC

Hope that helps

Last edited by otemu (2016-02-17 22:51:27)

Offline

#3 2016-03-23 17:39:11

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: Allowing user to change articles sort order

Hello,

If every article are showed on the page then the javascript solution is the best, because its fast.
If not every article are showed then you must edit the php.

Best Regards,
Adamos42


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations