Jump to content

Using the page fieldtype


cbuck
 Share

Recommended Posts

Hi. First time caller, long time lurker... actually short time lurker too...

So, I am digging this approach to content management... everything as an object. I can see the advantages right away, but I am not very smart, so... imma a fat dude running up hill. not pretty, and a little dangerous.

So in the process of beefing up my knowledge I am putting together a blog, just to see what I would be up against. I have found most to be easy enough, but I am having trouble wrapping my head around the page field type and how to grab access to those fields...

I have setup a page structure like so:

20120110-tki855rigr11u4ndtniq6hcuew.jpg

Am I on the right tract here, or am I totally missing something that should be obvious to a less daft individual?

In my blog_index template, how could I go about listing all the sections/categories and then make a list of all those pages that are in turn part of those section/categories?

Any help, or the occasional, "idiot" remark would be greatly appreciated. Thanks! Cheers.

Link to comment
Share on other sites

Hey welcome cbuck!

You're not an idiot, it's ok to ask and feel dumb... ;)

You should be able to easily grab page using an instance of the category page for example..

<?php

$cat = $pages->get('/blog-categories/news');
$pa = $pages->get('/blog/')->find("pagefield=$cat,template=blog-entry"); // "pagefield being your page reference field used for the categories

you could also check with multiple (PageArray) categories. Same goes for sections, just combine them if you wish.

You would just cycle through your categories/section and use the page object to find all blog entries with the code above. Pretty straight forward.

  • Like 1
Link to comment
Share on other sites

Am I on the right tract here, or am I totally missing something that should be obvious to a less daft individual?

You are on the right track

In my blog_index template, how could I go about listing all the sections/categories and then make a list of all those pages that are in turn part of those section/categories?

Here's an example that does everything. It lists all the categories, and then lists all the entries within each category. This may not be something you actually want to do, but I'm putting it here as an example that can be translated to different contexts. It assumes your blog entries have a page reference field names "categories" and a date field named "date".

$cats = $pages->get("/blog-categories/")->children();
echo "<ul>";
foreach($cats as $cat) {
 echo "<li><a href='{$cat->url}'>{$cat->title}</a>";
 $entries = $pages->find("parent=/blog/, categories=$cat, sort=-date");
 if(count($entries)) {
echo "<ul>";
foreach($entries as $entry) {
  echo "<li><a href='{$entry->url}'>{$entry->title}</a> {$entry->date}</li>";
}
echo "</ul>";
 }
 echo "</li>"
}
echo "</ul>";
  • Like 1
Link to comment
Share on other sites

Hey,

my blog (http://stadtpirat.net) runs with ProcessWire, too. So I'll write my way here in a couple of moments.

edit:

I guess it's solved right now. But Maybe it's interesting for you do read the answers to this post about how to work with categories in a ProcesssWire blog.

/ Nico

Nice layout!

I'm curious, as your blog obviously has a large number of posts, do you find it gets messy dealing with all of those the PW admin UI? That's been my one worry so far with the admin (and specifically using PW for blogging), scaling to groups with large numbers of children.

Link to comment
Share on other sites

I'm curious, as your blog obviously has a large number of posts, do you find it gets messy dealing with all of those the PW admin UI? That's been my one worry so far with the admin (and specifically using PW for blogging), scaling to groups with large numbers of children.

When you have more than 50 children, ProcessWire starts paginating them in the admin. Anything that has large numbers of children should generally have a default sort assigned to it (like date). I work with several sites that have thousands of pages and ProcessWire is specifically built for this sort of scalability in the admin and the API.

Link to comment
Share on other sites

When you have more than 50 children, ProcessWire starts paginating them in the admin. Anything that has large numbers of children should generally have a default sort assigned to it (like date). I work with several sites that have thousands of pages and ProcessWire is specifically built for this sort of scalability in the admin and the API.

If I remember correctly, you can also change that limit - I think on one site I've got it set at 25 before it paginates.

Link to comment
Share on other sites

You are on the right track Here's an example that does everything. It lists all the categories, and then lists all the entries within each category. This may not be something you actually want to do, but I'm putting it here as an example that can be translated to different contexts. It assumes your blog entries have a page reference field names "categories" and a date field named "date".
 $cats = $pages->get("/blog-categories/")->children(); echo "[list]
"; foreach($cats as $cat) { echo "[*][url="{$cat->url}"]{$cat->title}[/url]"; $entries = $pages->find("parent=/blog/, categories=$cat, sort=-date"); if(count($entries)) { echo "
[list]
"; foreach($entries as $entry) { echo "[*][url="{$entry->url}"]{$entry->title}[/url] {$entry->date}
"; } echo "
[/list]"; } echo "" } echo "
[/list]
"; 

Excellent! Thanks so much for the shove in the right direction with this. I guess my php chops are a bit underwhelming as well, it makes a lot of sense... after I read the replies. Thanks again!!! :)

Great group of folks here. Looking forward to learning and helping out when I can... :)

Link to comment
Share on other sites

When you have more than 50 children, ProcessWire starts paginating them in the admin. Anything that has large numbers of children should generally have a default sort assigned to it (like date). I work with several sites that have thousands of pages and ProcessWire is specifically built for this sort of scalability in the admin and the API.

Ah, that's fantastic. ProcessWire keeps getting better the more I learn about it.

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

×
×
  • Create New...