Jump to content

site structure question


webhoes
 Share

Recommended Posts

Hello,

I am working on a personal site of mine. I have a basic setup but run into some difficulties. As basis I am now looking at the demo (skyscraper) website. I have noticed that the setup is different to what I would have expected. I would like to know if I should change my setup to make more clever use of processwire.

 

Now I have a basic setup like this:

Specie (template specie)(can have 0 or more subspecies)(can be in 0 or more books)

        Subspecie (template specie)

Region (a (sub)specie can live in in one or more regions)

Book (a specie can be in one or more books)

Author (there can be more authors per book)

 

I want to have the following:

A google map with all species show on the map (reasonably working, but not per page of shown species)

A list of all authors with the number of books (can't get this done)

List of all books with the amount of related species in it (can't get this done)

A list of all species (working)(a google map of listed species of that page)

 

Basicly all the suff the skyscraper site has.

What I have noticed is that skyscrapers a childeren of cities. That made me think if I should take another approach.

Given on this info... what would you suggest.

 

 

Link to comment
Share on other sites

Would the following setup be logic? and give maximum flexibility for outputting to the front site, including a search form with keyword and field for continent, habitat, food and temperament.

 

Specie (parent with some own fields like title, body, images, etc.)

childs to specie: Continent (perhaps with own child called country), habitat, food, temperament, album (for photo's), etc.

 

Then also a page for author and the child for author is book

With a bidirectional link I can link specie to book.

 

 

Link to comment
Share on other sites

When deciding whether or not to use a parent-child structure to create a relationship, the questions I ask are:

1. Is this relationship a primary (very important) relationship?

2. Do I want the relationship to be revealed in the page URL? (Note that other types of relationship may still be represented in a URL via the URL Segments feature)

3. Is the relationship exclusive? (i.e. may the child only belong to a single category/parent - you want to avoid a situation where the same page would appear under more than one parent).

If the answer to any of these is "no" then I use a Page field for the relationship rather than a parent-child structure.

  • Like 2
Link to comment
Share on other sites

Thanks @LostKobrakai. I had already read this and read it again with this site in mind. If I am correctly is describes the basic normalization method. that would mean method 3 with the use of Page fields en bidirectional page fields.

@Robin S what do you mean a primary (important) relationship.

question 2: is most cases not as it makes the url too long

question 3: yes and no.

 

Turtle - title

           - body

          - habitat

         -

 

Habitat - title

               -body

 

http://site.com/turtletitle <- is ok

http://site.com/habitattitle/turtletitle <- should be ok too I think. Or should this be avoided?

 

Most parts that build up the turtle page are like habitats (temperament, location, food, specie name, album).

The main interest is the turtle, all others are extra information (but needed for a complete story).

 

As the demo site also has a different approach -> City -> cities (child) -> skyscraper (child)

What would be the benifit to use this with processwire. It seems like a reverse thought. But interesting to understand, for me atleast.

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

A parent/child relationship is no different than an exclusive one-to-one relationship with a page field. It just comes with the benefits of additional api support. The url is also to consider, but there are ways to work around that as well. So it boils down to your decision if you have a "primary" category you'd like to enforce (no child without parent). The demo page thinks it's primary enough for skyscrapers to be managed by city first and everything else later. This is in that case also shown in the url: http://demo.processwire.com/cities/new-york-city/chrysler-building/

Link to comment
Share on other sites

Thanks @LostKobrakai I understand.

Without using the child/parent setup how would I do the following.

page is turtle and linked to a habitat (another page) with a title Swamp.

 

How will I show the amount of turtles that have a link with Swamp?

Swamp (amount of turtles).

Turtle 1

- title

-body

-habitat (page reference) -> swamp

 

Habitats consistst of childs - swamp, river, lake, etc

 

I could not get that figured out in my own test site, hence I was looking into the child/parent solutions like the demo site.

 

 

Link to comment
Share on other sites

10 hours ago, webhoes said:

As the demo site also has a different approach -> City -> cities (child) -> skyscraper (child)

What would be the benifit to use this with processwire. It seems like a reverse thought. But interesting to understand, for me atleast.

Using a primary category in a parent-child relationship has some benefits:

  • Visitors can see the relationship demonstrated in the URL and breadcrumb navigation
  • The site structure is intuitive as visitors "drill down" through the page hierarchy to more specific pages
  • There is some SEO benefit
  • Finding a page in the admin page tree may be easier for site editors

But this type of page structure is only possible (or only sensible) when a child page will belong exclusively to a single category of that type. So in the case of the skyscrapers demo it works for the city relationship as a building can only ever be in one city. But it wouldn't work for the architect relationship as it is conceivable that a building could be designed by more than one architect. And you wouldn't want to have duplicated building content under two ore more different architect parents.

In the case of a turtle, you could for example use the taxonomical hierarchy in parent-child relationships: Trachemys scripta can only ever belong to a single genus, and so on up the hierarchy. But you wouldn't want to use "Native to" in a parent-child relationship as this would be both Mexico and the United States.

 

6 hours ago, LostKobrakai said:

$swamp = $pages->get("title=Swamp, template=habitat");
$swampAnimals = $pages->find("template=animal, habitat=$swamp");

 

@webhoes, matching to a page object / page ID like this is very reliable, but in most cases your Page field (habitat) will be limited to a single template and/or parent and the the titles of allowed pages will be unique. So you can cut out a step and do:

$swampAnimals = $pages->find("template=animal, habitat=Swamp");

 

  • Like 1
Link to comment
Share on other sites

Thanks @Robin S and @LostKobrakai!

All becomes more clearer every moment. I working on learning PHP and PW at the same time.

 

For the overview pages I have come up with this in the end:

$children = $page->children;
foreach ($children as $child){
    //$total = 0;
    $out .= "";
    $total = $pages->find("template=schildpad, habitats.title%=$child->title")->getTotal();
    $out .= "<a href='" . $child->url . "'>" . $child->title . "</a>(" . $total. ")<br>";
}

$content .= $out;

 

Until yesterday I made a structural thinking error. I used the template of habitat instead of turtle to get what I want from the turtle page. That doesn't work ofcourse.

Hence the frustration of not getting any results... But now I see stuff ;)

 

 

 

 

Link to comment
Share on other sites

I have made this function and it gives me the following error:

Error: Uncaught Error: Call to a member function find() on null in

function renderChildBlocks(PageArray $children){
    $out = "";

    foreach ($children as $child){
        $image = $child->images->first();
        $image = $image->size(300,169);
        $image = $image->url;
        $total = $pages->find("template=schildpad, habitats.title%=$child->title")->getTotal();

        $out .= "<div class='uk-grid-width-1-3'><a href='" . $child->url . "'><img src='" . $image . "'></a>";
        //$total = 0;
        $out .= "";

        $out .= "<a href='" . $child->url . "'>" . $child->title . "</a> (" . $total. ")<br></div>";
    }

   return $out;
}

 

Not as a function but on a template page it works perfectly. What did I do wrong?

This works...

 

foreach ($children as $child){
    $image = $child->images->first();
    $image = $image->size(300,169);
    $image = $image->url;
    $out .= "<div class='uk-grid-width-1-3'><a href='" . $child->url . "'><img src='" . $image . "'></a>";
    //$total = 0;
    $out .= "";
    $total = $pages->find("template=schildpad, habitats.title%=$child->title")->getTotal();
    $out .= "<a href='" . $child->url . "'>" . $child->title . "</a> (" . $total. ")<br></div>";
}
$content .= $out;

 

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...