Jump to content

When you have lot of subpages it's unhandy to browse them


procnewie
 Share

Recommended Posts

I'm basically trying to use ProcessWire as a really simple and clean blog.

At beginning with the basic profile i already liked the output.

But now that i start to have lot of pages under the same category, i find it hard to explore.

In my Pages, i actually made only few subpages that are my "categories" and inside them i made new pages as my "posts".
Using the default page template.

But they are listed together, and when they get to be too much, is feels wrong to show them all together.

Something like 10 posts per page listed + some bar to get older posts and older posts 10 by 10 would be more interesting.

It's just unpleasent to see a really long list and it also make really weird to use the sidebar to switch to another post.
It just make me think to remove the sidebar, but that would really slow to read other posts.

I know there is a Blog module, but it's really more than what i need!
I like to have just my categories, and when you get on them a list of Titles + the short description (maybe if i figure out would be cool to have the first n words of the post instead of the description so i don't have to write one)

I just want to customize the base template to not list all children, but to show only the first n and numbered bar to continue to older ones...

Since it look like a common behaviour maybe i can be pointed to some example or whatever.
By myself i can only figure out how to show only the firt n children, but i can't think about how to get multiple pages.

Thank you

 

 

Link to comment
Share on other sites

If you want to limit the amount of posts listed on a page, just use the 'limit=X' API call in your selector.

I think the docs are a little broken at the moment as a new site has just been launched but there should be plenty of examples available.

41 minutes ago, procnewie said:

But now that i start to have lot of pages under the same category, i find it hard to explore.

In my Pages, i actually made only few subpages that are my "categories" and inside them i made new pages as my "posts".
Using the default page template.

How are you handling categories? Can you screengrab your tree structure ?

Link to comment
Share on other sites

5 hours ago, BitPoet said:

Adding pagination to your category template should be quite straight forward. There are step-by-step instructions and examples at https://processwire.com/docs/front-end/markup-pager-nav/

This is really what i'm looking for!

But something is wrong. I tired this code but i get few numbers without titles and they go to nowhere:

		$results = $page->children("limit=10");
		$pagination = $results->renderPager();
		echo $pagination;
5 hours ago, Peter Knight said:

How are you handling categories? Can you screengrab your tree structure ?

It's really the default site. I only added subpages to the main tree.

5 hours ago, Peter Knight said:

If you want to limit the amount of posts listed on a page, just use the 'limit=X' API call in your selector.

That's what i already got. But you will not get multiple pages only by that.

 

Link to comment
Share on other sites

I'm sorry if  i double post but i don't see how to edit the previous one.

Apparently the code was incomplete, with that i got something that is near what i wanted:

echo "<ul>";
foreach($results as $result) {
    echo "<li><a href='{$result->url}'>{$result->title}</a></li>";
}
echo "</ul>";
echo $pagination; 

Except that i don't like the url of pages. "Page2, Page3" it's really ugly, i will try to customize it.

Link to comment
Share on other sites

Ok i have a good resault. I used only:

		$results = $page->children("limit=10");
		echo $results->render();

And added the example css to my main.css.

Now i'm trying to figure out how to have a sidebar that make any sense.

Edited by procnewie
Link to comment
Share on other sites

I followed my idea and at last is working. But if you know a better way to do this please show me.

			$results = $page->rootParent->children("limit=10");
			$pagination = $results->renderPager();
			echo "<ul>";
			foreach($results as $result) {
			    echo "<li><a href='{$result->url}$config->pageNumUrlPrefix$input->pageNum'>{$result->title}</a></li>";
			}
			echo "</ul>";
			echo $pagination;

 

Link to comment
Share on other sites

Pretty happy in the end. I copy pasted the 2 mains function used in the basic-page and edited according with what i wanted to get.

 

<?php

include('./_head.php'); // include header markup ?>

	<div id='content'><?php

		// output 'headline' if available, otherwise 'title'
		echo "<h1>" . $page->get('headline|title') . "</h1>";

		// output bodycopy
		echo $page->body;

		// render navigation to child pages
		//renderNav($page->children);

		$results = $page->children("limit=10");
		$items = $results;
		if($items->count()) {

			echo "<ul class='nav' role='navigation'>";

			// cycle through all the items
			foreach($items as $item) {

				// render markup for each navigation item as an <li>
				if($item->id == wire('page')->id) {
					// if current item is the same as the page being viewed, add a "current" class to it
					echo "<li class='current' aria-current='true'>";
				} else {
					// otherwise just a regular list item
					echo "<li>";
				}

				// markup for the link
				echo "<a href='$item->url$config->pageNumUrlPrefix$input->pageNum'>$item->title</a> ";

				// if the item has summary text, include that too
				if($item->summary) echo "<div class='summary'>$item->summary</div>";

				// close the list item
				echo "</li>";
			}

			echo "</ul>";

		}

		$pagination = $results->renderPager();
		echo $pagination;

		// TIP: Notice that this <div id='content'> section is
		// identical between home.php and basic-page.php. You may
		// want to move this to a separate file, like _content.php
		// and then include('./_content.php'); here instead, on both
		// the home.php and basic-page.php template files. Then when
		// you make yet more templates that need the same thing, you
		// can simply include() it from them.

	?></div><!-- end content -->

	<aside id='sidebar'><?php

		if($page->numParents > 1) {

			// rootParent is the parent page closest to the homepage
			// you can think of this as the "section" that the user is in
			// so we'll assign it to a $section variable for clarity
			$section = $page->rootParent;

			// if there's more than 1 page in this section...
			if($section->hasChildren > 1) {
				// output sidebar navigation
				// see _init.php for the renderNavTree function
				//renderNavTree($section);

				$results = $page->rootParent->children("limit=10");
				$items = $results;

				// if we've been given just one item, convert it to an array of items
				if($items instanceof Page) $items = array($items);

				// if there aren't any items to output, exit now
				if(count($items)) {

					// $out is where we store the markup we are creating in this function
					// start our <ul> markup
					echo "<ul class='nav nav-tree' role='navigation'>";

					// cycle through all the items
					foreach($items as $item) {

						// markup for the list item...
						// if current item is the same as the page being viewed, add a "current" class and
						// visually hidden text for screen readers to it
						if($item->id == wire('page')->id) {
							echo "<li class='current' aria-current='true'><span class='visually-hidden'>Current page: </span>";
						} else {
							echo "<li>";
						}

						// markup for the link
						echo "<a href='$item->url$config->pageNumUrlPrefix$input->pageNum'>$item->title</a>";

						// if the item has children and we're allowed to output tree navigation (maxDepth)
						// then call this same function again for the item's children
						if($item->hasChildren() && $maxDepth) {
							renderNavTree($item->children, $maxDepth-1);
						}

						// close the list item
						echo "</li>";
					}

					// end our <ul> markup
					echo "</ul>";
				}

			}

			$pagination = $results->renderPager();
			echo $pagination;

		}

		// output sidebar text if the page has it
		echo $page->sidebar;

	?></aside><!-- end sidebar -->

<?php include('./_foot.php'); // include footer markup ?>

 

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