August 18, 2010 at 8:56 pm #799
Let me explain this as it will make more sense.
When you add a post the latest one is shown on the slider on the left side. We add events to the slider every day. I need the closest date to be on the left and the furtherest date to be on the right. I know the logic for a blog is to show the last post first but here we are dealing with event posts. Manually changing the post published date is rather annoying.
So I was wondering if there is a simple way in the code to reverse the hierarchy of the posts shown in the slider. Lets say I have 5 events on August 31st and 2 events on august 20th. I want to have the august 20 events shown first on the left. Does this make sense?
Basically the slider needs to show post in a certain category being the closest to today’s date on the left. I am sure it is just a question of changing the mysql query and change a ASC or DSC somewhere but I can t find where the code for the slider is.
Thanks in advanceAugust 18, 2010 at 9:27 pm #32906
I solved it myself
open index.php and find
$additional_loop = new WP_Query(“cat=”.$k_option.”&posts_per_page=”.$k_option);
and replace it with
$additional_loop = new WP_Query(“cat=”.$k_option.”&posts_per_page=”.$k_option.”&order=ASC”);
This will put the closest date to today on the left instead of on the right. I hope this helpsAugust 26, 2010 at 3:31 am #32907
actually my code was wrong, I fixed it with
$additional_loop = new WP_Query(“cat=”.$k_option.”&posts_per_page=”.$k_option.’&orderby=meta_value&meta_key=Date&order=asc’);August 26, 2010 at 5:45 pm #32908
Ok I think I finally solved the issue and found another solution. Here is the final code. I am posting this so that people can learn from it and maybe it helps to solve other issues.
$todaysDate = date(‘Y/m/d’);
$additional_loop = new WP_Query(“cat=”.$k_option.”&posts_per_page=”.$k_option.’&meta_compare=>=&meta_value=’ . $todaysDate . ‘&orderby=meta_value&meta_key=Date&order=asc’);
I have a custom field called Date where I enter the date as 2010/08/26 for example.
The code above picks up posts between today and the future and orders them to display with the latest one starting on the left of the slider so you get something like
Event today – Event tomorrow – Event in 3 days – Event in 4 days
That way you do not have to remove the posts from the category manually
I hope this helps for those of us who are not php/WP gurus
The topic ‘Change slider date order oldest first, newest last’ is closed to new replies.