use ?orderby on dynamic pages iterative
-
Hey,
on landingpage I let my users sort the posts the way the want it, to achieve this I created a dropdown looking like this:
<div class="dropdown"> Sort by: <select id="myDropdown" name="sort-posts" onchange="document.location.href=location.href.split('?')[0]+this.options[this.selectedIndex].value;"> <option value="?orderby=date&order=ASC">Date asc.</option> <option value="?orderby=date&order=DESC">Date desc.</option> ...
This works fine for landing page, as there is no other
?
in the URL that could be attacked by the javascript to split before.But I need a solution that works for every page no matter if there are other
?
in the URL (like search page results or category/tag pages or any other dynamically created wp page…)So the javascript
.split
part is truly a makeshift.I need something like
At first dropdown use, add the value, at second or continuing use replace the value instead of appending it to the end again.
or with split function
At first dropdown use, add the value, at second or continuing use split only the last
?
If it were up to me, i wouldn’t use a dropdown, i would style it like a block nav, but thats further out of my imagination how to achieve this without the mentioned problems.
Hope you understand.
- The topic ‘use ?orderby on dynamic pages iterative’ is closed to new replies.