Jump to content

which template for directory?


mel47
 Share

Recommended Posts

Hi

I read tons of posts/tutorials about categories and variations on the same subject. However, I think there is something I don't understand or just use a wrong design. Does someone could kindly explain where is my problem?

Directory (basic-page template)

 --  Category (links template)

   ---  Link 1 (repeater)

 

I have no problem to output the content of the repeater on his own page of category. However, my problem is to list everything on the directory page. I suppose I can do a $page->find("template=links") but it make no sense to add that on a general basic-page template. Or do I should have a specific template for the parent page? Or some kind of function I can reuse? (I have the exact same problem for my gallery page with a category and their children)

Thanks.

Mel

 

Links template
$content .= $page->render('links'); 

/Fields/links
function renderLinks($page) {
foreach($page->links as $link) {
			echo "<h2><a href='{$link->http_link}'>{$link->title}</a></h2>";
			echo "<p>{$link->summary}</p>";
			echo "<p><a href='{$link->one_image->url}'><img src='{$link->one_image->url}' alt='{$link->one_image->description}' ></a></p>";
		}
	}
$content = renderLinks($page); 

 

 

Link to comment
Share on other sites

I'm not sure I understand what you want, but if you want categories like in wordpress, this is how I did them.

Spoiler

l1eMjMp.png

 

I have the above tree.

Taxonomies = taxonomies template

Genre, Audio = taxonomy template

Horror, Parody, Drama etc. = terms template

The templates have only the title field.

Then for each taxonomy (genre, audio, whatever you need) i created a field of type page, in the input tab choose the corresponding taxonomy for your field under Parent of selectable page(s) and a little lower you have the Input field type option i chose AsmSelect but you can try them out. 

Spoiler

1yyBDXb.png

Now go to the template for the page you want to add the categories and add the field(s) you made.

To display them i made a function so they link to an "archive" page.

function getTaxonomyTerms($taxonomy, $sep)
{
	$terms = '';
	$x = 1;
	foreach ($taxonomy as $t) {
		$link = '<a href="'. wire('config')->urls->root . $t->parent->name.'/'.$t->name.'">'.$t->title.'</a>';
		// if it's not the last item and a comma
		$terms .= ($x != count($taxonomy)) ? $link . $sep : $link;
		$x++;
	}
	return $terms;
}

// used like this
echo getTaxonomyTerms($page->genre, ', ')

This will link the terms to domain.tld/taxonomy/term i.e. domain.tld/genre/horror

The above will not work since I have removed the taxonomies from the url.

If this is what you need then i'll explain that part too.

  • Like 1
Link to comment
Share on other sites

From what I understand from your description, I think what you are looking for is

$page->child()
$page->child("selector")
$page->children()
$page->children("selector")

see: http://processwire.com/api/ref/page/

So you can access the children (links) of / from your directory (basic-page) and even filter them with a selector.
Then also iterating over them for whatever output:

foreach($page->children() as $link_page) {
	// do something with $link_page
	$link_page->that_link_repeater->each(...);
}

Is it this what you are looking for?

and yep, I think it would make sense to have a specific "directory" template when these pages have that specific purpose. I do this too for certain things.
 

cheers,
Steffen

Link to comment
Share on other sites

Thanks for answers. So I understand, from both of you, I should have a specific template and not an universal basic-page one. It's fine.

However I'm still unable to display all categories and all links on the page.

$links = $pages->find("template=links");
foreach($links as $l) {
    $content .=  "<li><a href='{$l->url}'>{$l->title}</a></li>"; //fine for displaying categories but missing the repeater.
   // echo $l->render();  doesn't work, copy all the page (including header, etc..)
}

So how I get all children but also their own children ? How I could refer to the repeater (which have already his template) ? It's probably something about the each() @blynx mentions. However I have no idea what to do with it and couldn't find any examples in the forum.
Sorry for my ignorance.

Mel

 

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