I’m working on a multilingual site for a client. The easiest way to do this (for free) I found was to use WordPress Multisite Language Switcher (http://lloc.de/msls). I’ve been working on this site for a while and it’s been working fine.
I’ve had a requirement to include a generic template, to allow the client to set various pages as a list page. I do this by getting the category ID on the basis of the title. From here, I list the relevant posts of that category. So far so good.
At the top of the page, I’ve to include a year dropdown for an archive of that category. This was included early in design without consultation and the client is adamant they want this in place.
I’ve used a plugin called ‘kwebble’ (http://kwebble.com/projects/wp-plugin-afac) before, which, even though no longer supported, does work well and solves many problems, and definitely works on a standard single site install.
My problem now is that on my archive page, I need to detect the category relating to the category of origin. I have tried outputting the category on the page and it makes no rhyme or reason. If I select 2014, I get one category (unrelated to the current). If I select 2013, I get a different category (again unrelated). All the while, these archive pages are under the URL: domain.com/blog/2014 etc. I can’t seem to get it to work without the /blog/ in the URL either.
I’m completely lost as to how to continue. Unfortunately I can’t show the site as it’s client privacy protected, but I can give samples of any code if it helps.
Any help would be much appreciated.
I thought I’d let you know how I resolved this.
After some discussion with a colleague, he made the point that adding a trailing year to the url, doesn’t affect the page displayed (I haven’t had time to find out the rationale for this yet) so:
/category/subcat/2011/
displays the same page as
/category/subcat/
This meant that I could parse the url and take the year from it and add it to the query.
I added this to the header to parse the url (I’m sure there are more efficient ways, but this worked well for me):
This might seem overly complex for what it does, but the logic works. If I do a test for a year on:
/category/subcat/
I need the code to know what to do with this bit. As I’m always going to need this part of the url, if the url is:
/category/subcat/2011/
I’ll need to trim 2011 off of it. This becomes more apparent further down.
I changed the title display from:
to:
This just means that on the parent page, I output the title and on a year sub-page, I can add in an “: Archives 2011” to the end of it to make it look like a proper archive.
I have a dropdown for the year at the top of the page. Previously this was populated with wp_get_archives, but I’ve scrapped that now. Now I need to have a first item called “All” which will revert to the parent, full list of posts and each subsequent item in the dropdown is a year.
Pretty straightforward stuff. I got most of the dropdown code from: http://wordpress.org/support/topic/archives-by-year-this-is-different
I probably need to add a category component to the MySQL query.
Finally, I changed the WP_Query, to include a year attribute. As this is left blank when the parent page is selected, it defaults to latest date. Otherwise, it shows just the year selected:
Just for good measure, I’ve left in the paging, which I use with the wp_pagenavi plugin.
The lesson here is that WordPress Multisite archiving is appalling. DIY is much better. I hope this helps someone else out there.
UPDATE: Have run into major problems with pagination in this regard. There seems to be no easy way around this, though working on a solution. WordPress just does not seem to play nice with category specific archives AND pagination.