Jump to content

what's the best way to structure this


roelof
 Share

Recommended Posts

Hello,

I have a site I want to make a PW site.

At this moment. I have a big section called dagboek where all the data is in. Some 800 articles.

As a layout im thinking about this one : http://20thingsIlearned.com

For my site I think it's the best way to have all the articles of a month and a year in the html code because it's look like 20things is working that way, Every page in a layer and only the current page visible.

My url looks like this on my old site   http://www.tamarawobben.nl/dagboek/year/month/pagenumber

Because of the layout im thinking about displaying one articles on each page.

Roelof

Link to comment
Share on other sites

I found a tutorial about categorizing and here the answers :

1. Q: What items on my site are the main items of interest?

A:   Things that happens the live of my daugther.


 

2. Q: What attributes of our items of interests are we interested in?

A:   articles


 

3. Do the things that happen  have sub-categories?

A: Yes. 

 

4.Can Articles belong to multiple sub-categories?

A: yes. year and months.

 

I hope the answers are right otherwise I hope someone can set me to the right track.

 

Roelof

Link to comment
Share on other sites

I don't think categories is the way to go here.

1. Nested Structure

This is a good example where the date structure could be used to create the articles. Then you would a) have the urls already and b) an easy way to create lists and such. Additionally add a date field to the article template so you can choose the date and use that for additional searching.

/dagboek/
   /2008/
      /januari/ // or use "01" as name whatever you like
         /article14012008/
         /article15012008/
      /februari/
         /article01022008/
   /2009/
      /januari/

Then loop the years and months in a simple nested php script using API. You don't need to check if there's a year or month with articles if you create months manually.

$years = $pages->get("dageboek")->children();
$out = '';
foreach($years as $year) {
    $out .= "<ul>";
    $out .= "<li><a href='$year->url'>$year->title</a>";
    if($year->numChildren) {
        $out .= "<ul>";
        foreach($year->children() as $month) {
            $out .= "<li><a href='$month->url'>$month->title</a></li>";
        }
        $out .= "</ul>";
    }
    $out .= "</li>";
    $out .= "</ul>";
}
echo $out;

Then on the years or months template file, you simply render out their children in any fashion you like and may add pagination using the built in Pager module.

You'll have urls like /dagboek/2008/01/page1, dagboek/2008/01/page2

2. Flat

The other route would be to use a flat structure and add articles to the /dagboek/ parent.

Then add a date field to the article template you can define the day this article is for. Then use a script that checks for articles (oldest, newest) and generate a menu with virtual urls for each year and month that has articles. The URL then can be resolved using urlSegments to show a list of articles for the selected month. You'd have to enable url segments on the dagboek template to make this work.

This is a script I created for generating a year month nested menu only for the ones that articles are found.

$datefield = "mydate";
$template = "article";
$url = $pages->get("/dagboek/")->url;

$newest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=-$datefield, limit=1")->first->getUnformatted($datefield));
$oldest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=$datefield, limit=1")->first->getUnformatted($datefield));

$out = '';
for($y = $oldest; $y <= $newest; $y++){
    $out .= "<li>";
    $out .= "<a href='#'>$y</a>";
    $month_out = '';
    for($m = 1; $m <= 12; $m++){
        $month_start = strtotime("$y-$m-1");
        $month_end = strtotime("$y-$m-1 +1 month");
        $selector = "template=$template, $datefield>=$month_start, $datefield<$month_end";
        if($pages->count($selector)) { // use count instead of find for fast query
            $month_out .= "<li><a href='{$url}$y/$m/1'>$m</a></li>";
        }
    }
    if(strlen($month_out)) $out .= "<ul>$month_out</ul>";
    $out .= "</li>";
}

echo "<ul class='menu'>$out</ul>";

Then, on the dagboek template something like:

if($input->urlSegment1 && $input->urlSegment2) {

    $year =  (int) $input->urlSegment1; // 2008
    $month = (int) $input->urlSegment2; // 02

    $start = strtotime("$year-$month-01");
    $end = strtotime("$year-$month-01 +1 month");
    
    // find the articles for within that current month
    $articles = $pages->get("/dagboek/")->find("template=article, date>=$start, date<$end, sort=-date");
    foreach($articles as $article) {
        echo "<h2>$article->title</h2>";
        echo $article->body;
    }
}

Just rough examples.

  • Like 12
Link to comment
Share on other sites

Sorry, I think it is not wise to give a respons when I just out of bed.

I;m thinking to use the nested structure only I have to look how I can best import my articles from my old site.

This one is made of a flat approach.

Roelof

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...