Jump to content
SamC

Whether to use pagination or not

Recommended Posts

I've got the structure:

multi-page-tutorial.png.2511cafad167f748382e6e6e793e7603.png

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:

list.thumb.png.e33c35907e367e0a86458bf97e4da7fc.png

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.

Share this post


Link to post
Share on other sites

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/ )

  • Like 1

Share this post


Link to post
Share on other sites
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. 

 

  • Like 1

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

==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; ?>:&nbsp;<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:

59ec89e621443_ScreenShot2017-10-22at13_06_06.thumb.png.3942619097d0b40b566ec2a189980a73.png

...renders:

59ec89ecb42c2_ScreenShot2017-10-22at13_06_17.thumb.png.65e66247f9ef316ab3f583475996e272.png

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.

59ec8ed9b37be_ScreenShot2017-10-22at13_27_33.thumb.png.a0fa898963cab3ff5b0420a85d809a95.png

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...