SamC Posted October 19, 2017 Share Posted October 19, 2017 I've got the structure: Tutorials (blog-index template) Any child of that (blog-entry template) I know I could have 'Page 1 of tutorial' being some sort of list which shows an extract of the children but I didn't want that here. Page 1 should look the same as the children. I've modified the template to include a menu at the top when on a page which (a) has children or (b) the parent pages' template is 'blog-entry'. The important bits are here: // blog-entry <?php namespace ProcessWire; ?> <?php // parent of multi page tutorial if ($page->hasChildren()): $entries = $page->and($page->children); ?> <ul> <?php foreach($entries as $index => $entry): ?> <li>Page <?= $index + 1; ?> <a href="<?= $entry->url; ?>"><?= $entry->title; ?></a></li> <?php endforeach; ?> </ul> <?php elseif ($page->parent->template == "blog-entry"): // parent and children of multi page tutorial $entries = $page->parent->and($page->parent->children); ?> <ul> <?php foreach($entries as $index => $entry): ?> <li>Page <?= $index + 1; ?> <a href="<?= $entry->url; ?>"><?= $entry->title; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-lg-9"> <?php if($page->bodyRepeater): ?> <?= $page->render("bodyRepeater"); ?> <?php endif; ?> </div> </div> </div> ...which outputs: at: /processwire-tutorials/page-1-title/ /processwire-tutorials/page-1-title/page-2-title/ /processwire-tutorials/page-1-title/page-3-title/ So in essence, 'it works'. A user can navigate between the parent and the children and they look like a coherent section. However, two blocks in the code above are repeated and I was thinking is there a way to do this with the built in pagination or a way to condense the code? The main problem I'm having is that I want to include the parent which means there are three conditions when displaying the menu: 1) Is a blog-entry post and has blog-entry children - show menu 2) Is a blog-entry post and parent is blog-entry - show menu 3) Is a blog-entry post and has no children - hide menu Or should I just get on with life? Just after some feedback really on how other people would handle something like this. Thanks for any advice. Link to comment Share on other sites More sharing options...
bernhard Posted October 19, 2017 Share Posted October 19, 2017 i think i would create a single blog-entry template with a repeater holding one ckeditor body-field. 1 repeater entry = single page blogpost more repeater entries = blogpost with multiple pages based on url-segments you could show the corresponding repeater item. without url-segment it would show the first. all other content would always be the same (like a comment section, for example would show up on all pages, like here: http://processwire.com/docs/tutorials/hello-worlds/ ) 1 Link to comment Share on other sites More sharing options...
dragan Posted October 19, 2017 Share Posted October 19, 2017 31 minutes ago, SamC said: Or should I just get on with life? Yes. Kidding aside: If you really want to split each tutorial into several pages, I would put them all on the same level. Perhaps use a tutorial-parent page for summary and introduction only (and maybe a "further links and downloads" section), and each child-page as actual tutorial-content. 1 Link to comment Share on other sites More sharing options...
abdus Posted October 19, 2017 Share Posted October 19, 2017 https://modules.processwire.com/modules/textformatter-pagination/ 2 Link to comment Share on other sites More sharing options...
SamC Posted October 19, 2017 Author Share Posted October 19, 2017 15 minutes ago, bernhard said: i think i would create a single blog-entry template with a repeater holding one ckeditor body-field. The blog-entry template has a repeater matrix field which is great for this. I can add body > image > body > code > image > body etc. 11 minutes ago, dragan said: Yes. Kidding aside: If you really want to split each tutorial into several pages, I would put them all on the same level. Perhaps use a tutorial-parent page for summary and introduction only (and maybe a "further links and downloads" section), and each child-page as actual tutorial-content. I was looking at this: https://processwire.com/docs/tutorials/simple-website-tutorials And seems that what you described is going on there. I didn't pay close enough attention to see that there is a parent summary page. Think I'll just make another template 'complete-tutorials' and as you say, list the entries under that. I could use the parent page to show what's actually going to be created as a teaser. I'm not a fan of multi-page tutorials (i.e. nasty SEO let's make 10 pages out of one) at all. They're a pita. However, i think there is a case when it comes to complete 'start to finish' tutorials, it makes sense to split them up into sections. Link to comment Share on other sites More sharing options...
SamC Posted October 19, 2017 Author Share Posted October 19, 2017 1 minute ago, abdus said: https://modules.processwire.com/modules/textformatter-pagination/ Yeah I thought of something like that, used to do it in Drupal 7. I think same level child pages would be easiest for me here. Link to comment Share on other sites More sharing options...
SamC Posted October 22, 2017 Author Share Posted October 22, 2017 ==UPDATE== I did this in the end using a single 'blog-entry' template. I have the structure: post 1 post 2 post 3 - post 3.1 - post 3.2 post 4 post 5 My menu is now in an include file: <?php namespace ProcessWire; ?> <?php // check if menu needs to be rendered before getting PageArrays if ($page->template == "blog-entry" && $page->parent->template == "blog-entry" || $page->template == "blog-entry" && $page->hasChildren()): // children of complete-guice parent if ($page->template == "blog-entry" && $page->hasChildren()) { $entries = $page->and($page->children); } // children of complete-guide parent elseif ($page->parent->template == "blog-entry") { $entries = $page->parent->and($page->parent->children); } ?> <ul class="list-group"> <?php foreach($entries as $index => $entry): // apply 'active' for current page $currentClass = ($page->id == $entry->id) ? "active" : ""; // change the parent blog post page title to 'Summary' $title = ($index == 0) ? "Summary" : $entry->title; ?> <li class="list-group-item <?= $currentClass; ?>">Page <?= $index + 1; ?>: <a href="<?= $entry->url; ?>"><?= $title; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> ...and to output it at the top of a blog post. Only shows if the page has children: // blog-entry.php <?php namespace ProcessWire; ?> <?php include("./includes/multi-page-menu" . ".php"); ?> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-lg-9"> <?php if($page->bodyRepeater): ?> <?= $page->render("bodyRepeater"); ?> <?php endif; ?> </div> </div> </div> <?php include("./includes/multi-page-menu" . ".php"); ?> ...with structure: ...renders: Only need one template now for anything that is a blog post whether it's a single page or has children. Now I can use the family settings properly without having to choose a template when Adding New > Blog Post. I'm quite a big fan of these settings. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now