Solved

Add link to Archive post code

Posted on 2012-04-05
3
279 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 110

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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

713 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