Jump to content
kaba86

Children Page submenu

Recommended Posts

Hello PW Community, really glad that discovered this CMS recently, it is very strange it took so long :) That idea of no front design limitations is just awesome!

Need to say that I have a bit of knowledge of html and css, but almost no php, so I need your help.

What I want to do is an article posting  cms, with this structure:
 

- Homepage

- Projects

- Articles

  -- Category 1

    --- Articles of category 1

  -- Category 2

    --- Articles of category 2

- About

- Contact

Found this ProcessWire Profile https://github.com/tutsplus/how-to-create-an-ajax-driven-theme-for-processwire

It covers almost all my needs, except the menu. When I add a childpage for this page http://artist.nicegrp.com/publications/world-world/ , World:World doesn't appear under Writings & Publications.

I need a menu that works like a breadcrumb, that shows on the menu the category that you are viewing. So when I'm in articles page, on the menu it shows only articles and it's categories. When I get into a category, that category takes state active link but doesn't show on the menu links and titles for contained articles. How can I do that?

Sorry for my long writing and English, it is not my native but I hope you understood what I need. Can you help me with that?

Thank you

 

Edited by kaba86
few edits

Share this post


Link to post
Share on other sites

For quick study how to structure your pages and menus, try first Blog Profile

You don't have to locate each article under category page. From Blog Profile you can learn how to use Page Reference field for category purpose.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for your response monchu, I will give it a try.

Still, if someone would like to help me out with code, would be really nice.

Here is the code of the menu from the Artist profile.

			<?php
				$children = $pages->get('/')->children;
				foreach($children as $child){
					$class = "";
					if($page->id == $child->id){
						$class = " current";
					}
					if($child->id == $page->parent->id){
						$class = " parent";
					}
					// echo nav links
					echo '<a name="'.$child->title.'" class="ajax-link'.$class.'" href="'. $child->url .'">'. $child->title .'</a>';
				}
			?>

Thank you

  • Like 1

Share this post


Link to post
Share on other sites

I don't know how @benbyf structured his site, i.e. neither the tutorial or the GitHub ReadMe mention any of that. Why don't you just ask him?

Personally, I would also tend to use page reference fields to create categories. Together with URL-segments (and maybe altering the JS a bit for the AJAX stuff and history.js functionality) this would be my choice of how to set up such a site.

Looking at that code block above, it seems like you just need to check if $child has children (check for one more level deeper), and do some if/else stuff...

  • Like 2

Share this post


Link to post
Share on other sites

Hi @kaba86 as @dragan mentioned you can simply add another foreach loop to check another level down. I would defiantly check out some tutorials on using processwire to get yourself kickstarted in the right direction and theres lots of quality tutorials not to mention some of my own. https://processwire.com/docs/tutorials/

<?php
				$children = $pages->get('/')->children;
				foreach($children as $child){
					$class = "";
					if($page->id == $child->id){
						$class = " current";
					}
					if($child->id == $page->parent->id){
						$class = " parent";
					}
					// echo nav links
					echo '<a name="'.$child->title.'" class="ajax-link'.$class.'" href="'. $child->url .'">'. $child->title . '</a>';
                  	
	                // new code below
                    $childChildren = $child->children;
                    foreach($childChildren as $subChild){
                      	$class = "";
	  					if($page->id == $subChild->id){
							$class = " current";
						}
						if($child->id == $page->parent->id){
							$class = " parent";
						}
                      
                      echo "<div class='sub-item'>";
                      echo '<a name="'.$subChild->title.'" class="ajax-link'.$class.'" href="'. $subChild->url .'">'. $subChild->title . '</a>'; 
                      echo "</div>";
                    }
				}
			?>

The above is not optimised or elegent - just off the top of my head. I seem to remember one of the default themes has a funciton in it's _func.php file that gives you a nest page list given a page varible (and optional max depth) so you could use that too. Hope that helps (also please post you website when its done :)

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you @benbyf for your help, appreciate it :) I will look for that function on default profiles, will replay when I get done what I want. Going to test now your addition to the code.

Share this post


Link to post
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.

  • Similar Content

    • By rjgamer
      Hi,
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
      Thanks.
       
    • By rjgamer
      Hi guys,
      the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.
      Does anybody know what I did wrong in my code?
      if ($input->urlSegment(1) === 'redirect') { $page->of(false); $page->redirect_last = time(); $page->redirect_counter += 1; if ($page->save('redirect_counter')) { $session->redirect($page->website_url, 302); } } Thanks.
    • By theoretic
      Hi there! And thanks for Processwire!
      I have an interesting task which i cannot fulfill as i want. Maybe someone could help me please?
      Let's imagine a simple page structure of this kind:
      Category 1
      + Item 1.1
      + Item 1.2
      Category 2
      + Item 2.1
      + Item 2.2
      My task is to attach some items to more than one category, at least to show some items on different frontend category pages. With PW, it's a piece of cake. I've just created a field called Items (of type Page Reference) and attrached it to Category template. Since i have lots of items inside each category i preferred to use Page Autocomplete input for my Items field. The pages available for autocomplete are restricted by a very simple selector:
      template=item
      It works like a charm. But later i decided to make this autocomplete even smarter and to exclude current category children items from it. I tried to update my selector this way...
      template=item,parent!=(page)
      ...and oops, this broke my selector. My autocomplete founds nothing. Sorry, i had to replace the square braces by () because of this forum limitations, i swear i'm using square brackets in real-life selector!
      What am i doing wrong? And is there any way to include current page info in autocomplete-related selectors? Thanks in advance!
       
    • By louisstephens
      So I ran into a very strange issue today. I have a template with a pagetable and I went to add an item to it, when I went to select an image (for an image field) the page instantly threw up an error
      "ProcessPageSearchLive: No search specified"
      The page's content also switched to the image attached. This all worked perfectly last week (local mamp box). Has anyone experienced this before, and how did you solve it?
       

    • By Pip
      Hi everyone, 
      Is there a way for us to replicate the "http://mydomain.com/processwire/page/edit/?id=xxx" and change the template to match my site template? 
      I'm terribly happy with the admin / backend page edit. It covers literaly everything I want to empower my non super admin user in updating pages such as validation, repeater management, file upload. 
      I wish not to allow the users to see the backend for both security and aesthetic reasons. 
      Thanks and hope to hear from you soon. 
       
×
×
  • Create New...