Home › Forums › JavaScript › Dynamically change post query
- This topic is empty.
-
AuthorPosts
-
January 5, 2011 at 4:10 pm #31166avandelayParticipant
I’m currently using the following code to display posts from a particular category from a particular month and year.
It works well, but I would like to make the page dynamic so that the visitor can select a month and year from a drop-down menu and have the content change according the the values selected. See example (1) (2).
I’m basically looking for a way to translate the action of selecting a month into changing the value of ‘monthnum’ in the queryposts()
I don’t have much experience with ajax, but I have a feeling that might be useful for this job.
Can anyone think of a way to do this?
Thanks!
-ArtJanuary 5, 2011 at 4:44 pm #67362BobMemberWhat if you make the value of monthnum a variable, which is taken from a dropdown list or something like that?
Like this:
$monthvar = $_POST["month"];
query_posts("cat=3&monthnum=$monthvar&year=2011");
?>I don’t really understand what you want though so I might be wrong here.
January 6, 2011 at 1:27 am #67336avandelayParticipantThanks Bob,
Do you know how I could make that work with a drop-down menu?
I would like to have a drop-down menu that contains a list of the months.
If the user selected “January” I would want the content on the page to reload, only showing posts from January.I understand that in the drop-down menu, the name “January” would correspond to a value of 1; “February” to a value of 2, and so on.
I don’t know how to write code that would replace the current value of $monthvar in the query_posts(), when January is selected.
I also don’t know how to write code that would tell the browser to reload new content based on the new values in query_posts() after January is selected.If anyone could provide me with some example code I would be greatly appreciative.
Thanks!
January 6, 2011 at 2:46 am #67311BobMemberHmm, what you’re asking for (content being reloaded) will require Ajax indeed, but I don’t know any Ajax unfortunately. So I guess you’ll have to wait ’till someone shows up who does. Good luck anyway.
January 6, 2011 at 8:31 am #67318TT_MarkMemberYep, what you are looking for is an automatic postback using AJAX which triggers when you make a change to the dropdown menu.
I’d personally use JQuery for this and, if you take a look at the documentation on their website, it is relatively straightforward.
Have a go yourself and let us know if you get stuck. There are plenty of people here willing to help
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.