Did you have any luck with this mate?
Im after doing the exact same thing, to sort posts by:-
ASC
DESC
# Comments
TAG.
Did you manage to do this, im stuck!
Cheers
Paul
Did you try the code? I changed it a little bit. Try it with this before a loop you want sorted: http://pastebin.com/LCFS945E
Cheers, ill try the code now thanks,
This is a bit more info on what im after: –
I want to be able to display a drop down list of tags on the archives.php file to enable a sort/filter on a list of posts.
For example, i have 20 posts, each 5 posts have a tag of “Cheshire”, 10 have a tag of “London” and the other 5 have a tag of “Kent”.
The tag = an Area.
I want to be able to select tags (areas) that are only active on the posts in a drop down list.
So there are only Cheshire, London and Kent. I dont want to display the other 30+ different areas. Only the areas / tags that are asigned to the posts listed.
Then when they select one of the tags such as Kent, it will then display posts only for Kent?
So what im after is a sort function in a dropdown for active tags on the post lists page?
So, you want the tags from the posts that are normally displayed on an archive page in a dropdown?
Yeah just the tags in a dropdown so i can filter the posts by area.
This might give you a better idea of what im trying to do: –
www dot myweddingreviews dot co dot uk/photographers
Cheers
Try it with multiple loops. the first loop to get all the post tags and sort them alphabetically. The second loop to show the posts and to sort them by area (if one was selected).
example: http://pastebin.com/Q6iaUKi5
Hi mate,
Nearly working, the site seems to crash when i include the second loop at the end: –
<!-- second loop -->
<?php if ( have_posts() ) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- rest of your loop -->
Can see what its like so far: –
www dot myweddingreviews dot co dot uk/photographers
Everything above that works, but when i include that 2nd loop my site doesnt display.
The code for the posts i have is: –
[Code moderated as per the Forum Rules. Please use the pastebin]
From your loop remove:
<?php query_posts($query_string . '&orderby=rand');?>
From my code remove at the end:
<!-- second loop -->
<?php if ( have_posts() ) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- rest of your loop -->
I didn’t include a second loop in my code. Just the beginning of a loop.
do i need to do something after the 2nd loop? Not good at php, but im guessing thats why its not working when i select an area from the drop down?
Or is it a conflict from the code i have pasted above?
Yesssssssssssssss!!!
Brilliant, thank you so much! Awesome.
Im guessing this would work a similar way if i wanted to add another fliter such as categories ie: Photographer, Wedding Cakes, Dresses etc?
MUCH APPRECIATED! π
Can you paste and submit the full code of the template file with my code in it into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.
It takes the current category and gets the tags from the posts displayed (so not all tags). So you can use it for Wedding Cakes, Dresses etc. If the tags are always “area’s”.
Here is the link to the archives.php file: –
http://pastebin.com/WAHLgVPb
The area uses tags, which is working thanks!
And the wedding topic uses “category” in wordpress.
So photographers, dresses, cakes, etc are all categories.
Thanks π
If it’s a (any) category Page it will work.
The only downside of doing it this way is that it doesn’t work for people who have javascript turned off.
I hope this resolves it for you.