Not sure if this is the appropriate place to ask this.
I have a blog using wordpress. i have customized it quite a lot and continue to do so. I am currently using the function wp_get_archives to get the number of posts created in each month. However i want to format these results on my blog in another way rather than just a list etc.
currently the output is:
<li><a href='url' title='May 2008'>May 2008</a> (3)</li>
I would like to be able to parse this output and then print it in a different format. I am having a tough time knowing how to parse the output.
So my ultimate goal is to create a table for each calendar year.
For 2007 the table will have 2 rows and 12 columns. Row one will contain Jan, Feb, Mar etc and row two will contain the number of posts for the month in the cell above it. Both the month and the number of posts will be clickable.
Then underneath this 2007 table i will have a 2008 table.
Each table will span the column with of my blog which is about 900 pixels and the height of the table will be about 80 pixels
Shoot! I'm so sorry I didn't get back to you. I totally forgot about this thread. I just now noticed it again.
Would you mind making a little image which illustrates what you want? Even something as simple as a BMP from Windows Paint that you throw together real quick or something. Or even a mock-up HTML file if you want to go that far. I just want to be sure what exactly you're going for. I think I might get what you're saying but I just want to be really sure.
So i have attached a jpg of the table. Of course i will end up creating some css for it to make it fit in with my blog, but for now this is the basic style i am looking for.
OK! I see what you mean. I'm gonna do some testing to see how I can get that to work. I think I have an idea. Usually I'd just be trying to explain to you how to do it but in this instance I think it might be better for me to figure it out and then try to explain how I did it. I'll post back when I have something. Shouldn't be too long.
<table id="archives">
<?php $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC");
foreach($years as $year) {
$months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE YEAR(post_date) = $year AND post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC"); ?>
<tr>
<td><?php echo($year) ?></td>
<td>
<table>
<tr>
<?php foreach($months as $month) {
$month_text = date('M', mktime(0, 0, 0, $month, 1, $year)); ?>
<td><a href="#month"><?php echo($month_text) ?></a></td>
<?php } ?>
</tr>
<tr>
<?php foreach($months as $month) {
$posts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE YEAR(post_date) = $year AND MONTH(post_date) = $month AND post_status = 'publish' AND post_type = 'post' ORDER BY post_date ASC"); ?>
<td><a href="#month"><?php echo($posts) ?></a></td>
<?php } ?>
</tr>
</table>
</td>
</tr>
<?php } ?>
</table>
Let me know how that works out. Hopefully that does what you need. I think the code is pretty simple. You should be able to tell what it's doing I think...
That looks like it works! Thanks a lot
I tested it on my sample blog and all seems good. I just need to create the links and format the table. I'll let you know if i have anymore problems
Bookmarks