| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Senior Member
Join Date: May 2005
Location: St Helens
Posts: 473
|
Wordpress Archives
Anyone know if its possible to display a archive page listed like this: 2006 Title 1 Title 2 Title 3 2005 Title 1 Title 2 etc ive found nothing on the wordpress sites and the various plugins that there are to customise the archive page dont seem to work in this way. Cheers |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,195
|
Sorry never used wordpress, but surely you can make your own php page read from the same database. What I do is get PHP to get the current year, then put it into a loop doing a mysql (select where date = blah) query on each loop, then reducing the year by one, and have it print out the results until it can't find any. That way you don't ever have to update it. |
|
|
|
#3 (permalink) |
|
Senior Member
Join Date: May 2005
Location: St Helens
Posts: 473
|
that sounds like a solution, but something im going to have to look into, php is like trying to read french to me, i can get some of it but most of it makes no sense. i have been thinking of a work around myself, which would be a bit less automated, than your suggestion. cheers freelancr |
|
|
|
#5 (permalink) | |
|
Will work for Marmite
Join Date: May 2007
Location: Sapporo, Japan
Posts: 573
|
Quote:
I wouldn't bother with all that. It sounds like you want the whole lot (posts from every year) so all you need is: Code:
No point in running multiple queries when one will do. The ORDER BY is probably not necessary, but keep it just in case. Once you've pulled all the data, just munge it in PHP in while loop. |
|
|
|
|
#6 (permalink) | |
|
Senior Member
Join Date: May 2005
Location: St Helens
Posts: 473
|
Quote:
so do i just stick that in the div on the php page where i want it? does it not need to be in any sort of php tags? cheers |
|
|
|
|
#7 (permalink) |
|
Senior Member
Join Date: May 2005
Location: St Helens
Posts: 473
|
from what you gave me Snowshiro and from a page on the wordpress doc site here ive managed to cobble this code together Code:
which is almost giving me what i want with a couple of exceptions. 1) the year is displayed above each post title, when i want to group everything from say 2006 under that year ie 2006 title title title 2) pages are also included in the list. is there a way i can exclude them. cheers |
|
|
|
#8 (permalink) |
|
Will work for Marmite
Join Date: May 2007
Location: Sapporo, Japan
Posts: 573
|
Hehe... That's truly horrible looking code A couple of tips: 1. You don't need to put php tags around every statement. You can enclose as many lines of PHP as you want. Just break out if you want to revert to regular HTML. 2. Your query is pulling back the entire contents of the wposts table, although this isn't necessarily a problem as MySQL is pretty efficient and unless you make thousands of comments, the data structure won't get that big. I must admit, I'm not familiar with Wordpress classes (I've tended to write my own code from scratch before) but I would guess from what you have there that the_time('Y') is where your problem lies. It looks like a function which displays the date/time formatted by the string it's passed. In this case, one would assume 'Y' indicates year. Since this sits in the foreach loop without any kind of test, it's going to display the date on every iteration, as you confirmed in your post. However, since the_time() presumably displays the time rather than just returning it, we're going to need to replace it with our own code (personally, I hate using functions like this that echo their results rather than returning them to the calling code, but each to their own). You've got two choices - either write your own query or rummage through the docs a bit more and find out how to access the date value directly. Unfortunately my job is a bit mental at the moment and I already have a backlog of people who have been PMing me about other stuff, so if I get any time later I'll take a look at it. Otherwise hopefully someone else can give you a quick answer. |
|
|
|
#10 (permalink) | |
|
Senior Member
Join Date: Oct 2006
Posts: 2,195
|
Quote:
You seem to have things sorted already. I was going to give you a raw PHP script for accessing the database, a real world example of what Snowshiro wrote. But it looks like with wordpress you may be better off using the existing OOP classes. |
|
|
![]() |