Jump to content

Template & template file creation


Recommended Posts

I'm new to PW -- downloaded and went through tutorials -- and need advice in best approach to template creation.  I want to get started on the right track.  The website will consist of approx. 300 how-to articles, a list of which (with thumbnail image) is to be displayed on category pages (main menu - 6 categories) under various subtitles (not part of menu).


  -- Subtitle1:

    ---- Article1

    ---- Article2

  -- Subtitle2:

    ---- Article3

    ---- Article4

  -- Subtitle3:

    ---- Article5

    ---- Article6


  . . .

About 10% of the articles  need to be listed under multiple categories.  In creating Article template & template files for delayed output pages, what would it be the optimal way to organize template and template files?  (A. having two separate template/template files for single and multiple category articles -- simply placing the single-category articles in their respective admin hierarchical page tree and doing what with multiple-category pages?,  or B. -- having a single template for all pages that would have 3 category fields (and their respective subtitle dropdown selection fields), using only the first category field for single-category pages?, or C. something else.)

What would the resulting admin hierarchical page tree be?

What modules would be helpful in creating this site?

Thank you!

Link to comment
Share on other sites

I'm working on something like this. Here's how I did it so far.

Templates x 4:

/tutorials/ (blog-index)
/tutorials/tutorial-title/ (blog-entry)
/tags/ (tag-index)
/tags/tag-name/ (tag-entry)

Tree structure:


blog-entry has a multiple page ref field called 'tags'...


...like so:


tag-entry has a multiple page ref field called 'blogPosts'...


...like so:




(this module has been very very useful so far, written by @Robin S and recommended to me by @abdus)

The fields are connected thus:


So when I create a tutorial (blog-entry template), I can select a bunch of tags (or create new ones):


...the page created with 'blog-entry' is automatically added to the associated tags in the 'blogPosts' page ref field:


So now you have the posts listed under the actual tag, it's as simple as just iterating over the 'blogPosts' page ref field:

<?php namespace ProcessWire; ?>

<div class="container py-5">
  <div class="row">
    $tags = $pages->get("/tags/")->children;
    foreach ($tags as $tag):
      if (count($tag->blogPosts)):
  <div class="col-md-4 mb-5 px-md-5">
    <h2 class="display-4"><a href="<?= $tag->url; ?>"><?= $tag->title; ?></a></h2>
      // return PageArray of all items in blogPosts ref field
      $posts = $tag->blogPosts;
      // sort the PageArray
      // only want first 3 items
      $posts = $posts->slice(0, 3);
      // loop through the 3 items
      foreach ($posts as $entry):
    <p><a href="<?= $entry->url; ?>"><?= $entry->title; ?></a></p>

    <?php endforeach; ?>




Still not decided how to list them when there are multiple tags, but hope this gives you some ideas.


  • Like 3
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

  • Recently Browsing   0 members

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