开发者

How to change wordpress query_posts by clicking a link?

I have开发者_高级运维 posts queried by a taxonomy, and I'd like to a have an option available for the front-end user to re-order the posts. Is this clear? Example: 20 movies ordered by date (when the movie was premiered) and the user clicks a link to order the movies DESC or ASC by date.

What's the best way to achieve this? Should I use ajax or something to change the query_posts? I'm a bit (?) lost!

I've tried using ?order=ASC&orderby=Data after the url in links, but it only seems to work on "regular" loop.

Thanks, Dani.


What about passing the arguments by GET as you suggest, and then manually composing your custom query with query_posts or whatever you are using?

The link to change order:

<a href="?order=DESC&orderby=Data">Data, descencing</a>

And the PHP:

if( !empty($_GET['order']) ) $order=$_GET['order'];
else $order='DESC'; // default

if( !empty($_GET['orderby']) ) $orderby=$_GET['orderby'];
else $orderby = 'Data'; // default

query_posts('orderby='.$orderby.'&order='.$order);

It would probably be smoother for most users to do it with AJAX so the page doesn't reload, but it has its own drawbacks (accessibility wise) and you would need a bit more work to implement it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜