Solved

Add link to Archive post code

Posted on 2012-04-05
3
273 Views
Last Modified: 2012-04-05
I am creating a blog and need to have an 'Archive' section.

The year and months display ok using this code...

 <?php foreach ($data as $year => $months) {
    echo $year.'<br>';
    foreach ($months as $month => $count) {
            echo date("F", mktime(0,0,0,$month,1,2000)).'('.$count.')<br>';
    }
} ?>

Open in new window



However, i'm not sure how to add a link. When you click on a month you need to redirect to archive.php and send $month over in the URL so the results page can display all posts from that month.

Any ideas where I add the link to the above code?
0
Comment
Question by:BrighteyesDesign
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37811767
Maybe something like this?
<?php // UNTESTED CODE
foreach ($data as $year => $months) 
{
    echo $year.'<br>';
    
    foreach ($months as $month => $count) 
    {
        $mnth = date("F", mktime(0,0,0,$month,1,2000));
        $link 
        = '<a href="path/to/script.php?month='
        . $mnth
        . '">'
        . $mnth
        . '</a>'
        . "($count)"
        . '<br/>'
        . PHP_EOL
        ;
        
        echo $link;
    }
}

Open in new window

0
 

Author Comment

by:BrighteyesDesign
ID: 37811850
Ray, you're an absolute superstar, thanks for that!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37811864
Thanks for the points!  That "vertical layout" for concatenated strings is something I learned from a SQL guru.  I've found that it makes the code very easy to read and get right the first time.  All the best, ~Ray
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now