Old 17-06-2007, 16:21   #1 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
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
  Reply With Quote
Old 17-06-2007, 18:04   #2 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
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.
  Reply With Quote
Old 18-06-2007, 03:58   #3 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
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
  Reply With Quote
Old 18-06-2007, 06:20   #4 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,195
I have some code kicking around on my Linux drive that may be of use to you, I'll try and post it up today.
  Reply With Quote
Old 18-06-2007, 07:29   #5 (permalink)
Snowshiro
Will work for Marmite
 
Snowshiro's Avatar
 
Join Date: May 2007
Location: Sapporo, Japan
Posts: 573
Quote:
Originally Posted by freelancr
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.

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:
SELECT post_date,post_title FROM wp_posts ORDER BY post_date;

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.
  Reply With Quote
Old 18-06-2007, 09:31   #6 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 473
Quote:
Originally Posted by Snowshiro
Code:
SELECT post_date,post_title FROM wp_posts ORDER BY post_date;

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
  Reply With Quote
Old 18-06-2007, 14:18   #7 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
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:
<?php $querystr =" SELECT wposts.* FROM $wpdb->posts wposts ORDER BY post_date DESC"; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php foreach ($pageposts as $post): ?> <?php the_time('Y') ?> <?php setup_postdata($post); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3> </div> <?php endforeach; ?> <?php endif; ?>

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
  Reply With Quote
Old 18-06-2007, 19:46   #8 (permalink)
Snowshiro
Will work for Marmite
 
Snowshiro's Avatar
 
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.
  Reply With Quote
Old 19-06-2007, 03:50   #9 (permalink)
dpc036
Senior Member
 
dpc036's Avatar
 
Join Date: May 2005
Location: St Helens
Posts: 473
Quote:
Originally Posted by freelancr
I have some code kicking around on my Linux drive that may be of use to you, I'll try and post it up today.

any luck finding your code freelancr?
  Reply With Quote
Old 19-06-2007, 07:54   #10 (permalink)
freelancr
Senior Member
 
freelancr's Avatar
 
Join Date: Oct 2006
Posts: 2,195
Quote:
Originally Posted by dpc036
any luck finding your code freelancr?

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.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8