dlen
Members-
Posts
35 -
Joined
-
Last visited
Everything posted by dlen
-
Hi there, i just want to share the code of what the subject line says. The pages to appear in the menu have a custom field "in_main_menu" of type checkbox checked. The item <li>s of the actually shown page and in the direttissima upwards - except home - get the class "current". The item <ul>s of submenus get the class "submenu". This is basically Ryans Code from here run through a meatgrinder. I hope useful for any beginners like me looking for a solution to a similar problem. Any improvement welcome! Now the code: /** * A recursive menu containing home. (It is added to the list of menu items while $level =1). * In order to be included, a page must have a custom field "in_main_menu" of type "checkbox", * and the latter has to be checked. * All submenu <ul>s get class "submenu". * All <li>s in the direttissima upwards of the page shown - except home - get the class "current". * Takes $root out of the recursion in order to not have all pages twice. * All menu items, that have children, do not have a link to their content, but act merely as switches. * You can switch this behaviour off by replacing * * $href = ( $item == $root || !$item->numChildren ? "$item->url" : "#" ); * * with * * $href = $item->url; * * Or you can make it conditional by querying a second custom field "has_own_page", e.g. * * $href = ( $item == $root || !$item->numChildren || $item->has_own_page ? "$item->url" : "#" ); * * Intended to be used without arguments, i.e. "selectiveMenu();" , i.e. always starting with site root. */ function selectiveMenu(Page $root = null) { $shownPage = wire('page'); if(is_null($root)) $root = wire('pages')->get('/'); $level = count($root->parents); $ul_class_string = (($level > 0) ? "class='submenu'" : ""); $out = "\n<ul {$ul_class_string}>"; $parents = $shownPage->parents; $items = $root->children; if ($level == 0) $items->prepend($root); foreach( $items as $item) { if ($item->in_main_menu) { $s = ''; $li_class_string = ( ( $parents->has($item) && $item !== $root ) || $item === $shownPage ? "class='current'" : "" ); if($item->numChildren && $item !== $root) { $s = str_replace("\n", "\n\t\t", selectiveMenu($item)); } $href = ( $item == $root || !$item->numChildren ? "$item->url" : "#" ); $out .= "\n\t<li {$li_class_string}>\n\t\t<a href='{$href}'>{$item->title}</a>$s\n\t</li>"; } } $out .= "\n</ul>"; return $out; }
- 1 reply
-
- 1
-
- navigation
- recursive
-
(and 1 more)
Tagged with:
-
Hi , a bloody beginners question: in the function declaration you start with <?php, but you don't end with ?>. Why is this? Thanks...
-
I found a crude but apparently working solution. I ask if a certain session variable $session->secondvisit exists, which is certainly not the case in the beginning. If not, it will be created and a crude language switch starts working. if (!$session->secondvisit) { $session->secondvisit = true; $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); if (strpos($locale, 'de') === 0) { $user->language = 'de'; } elseif (strpos($locale, 'es') === 0) { $user->language = 'es'; } } This is standing in front of <html>. Any constructive critique welcome. For any language other than German or Spanish, the default language english will be in effect. As the language string is e.g. "de_DE", strpos returns either 0 or false. So querying simply if (strpos($locale,'de')) { ..... } will not work, because the position of 'de' in 'de_DE' is 0 and php takes a 0 for a false, if I am correct.
-
Gallery: A photo album module (preview)
dlen replied to kongondo's topic in Module/Plugin Development
Hi, I would be interested in this work of yours, too... -
Hi, a beginners question to the $form->action = "./" part: Couldn't you just leave the action-attribute out, just do not write it? AFAIK this would have the same effect. I read that "./" means "same directory" and is only in this context interpreted as "same url/file/script".
-
kongondo, do you have a donation pathway, i d like to buy you 2 coffees or something.
-
Dear forists, this post is just to help others to find the solution to the issue, which has been mentioned and solved here and in the following post by hansv, and which is currently difficult to spot via Google. Snippets of the error message are No menu items found! MarkupMenuBuilder.module(88) To repeat the explanation given, kongondos Menu Builder, which is really a great piece of software, creates named menu datasets, aka pages, and can in monolingual sites render the respective menus by using the menu dataset / page name. In multilingual sites,though, it currently cannot. One has to resort to other ways of addressing the prepared menu dataset, by its ID. To get the latter, open the menu editing page and look into the address bar. Now render your menu with a string analog to $menumodule->render(1023); (added) Kongondo noted "that you can also pass a menu $page or an array of menu items in addition to the ID." I don't know how exactly to get a menu page object into a variable, so I resort to the ID method. Of course, you can include the options as explained in the readme. This is all redundant information but may be it helps somebody to get it faster.
-
How to switch profile from "beginner" to "default" without new install?
dlen replied to dlen's topic in Getting Started
wow thanks for the quick answer! It takes only 3-4 minutes to reinstall, if the directory is once empty. The latter is a problem with ftp. I logged into the site admin interface of the provider, which has a file manager, and allows to accomplish the complete delete in 2 s. -
Dear forists, I just installed pw, using the site profile "site-beginner", having unchecked all others. Now I'd like to explore the "site-default" profile but found out fast, that just replacing the /site/ - directory content by the content of the /processwire-master/site-default/ directory leads only to 404s. This is of course because I replaced this way also the config.php, which throws away the database connection parameters. Are there any other aspects to consider? Or is a quick reinstall the best way to switch site profiles? Any positive comment welcome. Dominik
-
Hi folks, it showed up again with a shared hosting account at dogado.de. I could remedy it by switching off html5 upload analog to the best answer at the top. Only, in the meantime there has been built in an automatic switch between InitHTML5('') and InitOldSchool() at line 381 or so. The code is if (window.File && window.FileList && window.FileReader && ($("#PageIDIndicator").length > 0 || $('.InputfieldAllowAjaxUpload').length > 0)) { InitHTML5(''); } else { InitOldSchool(); } and this switch criterion fails in the case of said provider. I replaced it with the simple statement InitOldSchool(); which is kind of crude, but it works. In case somebody else wants to do the trick: you have to replace the file InputfieldFile.min.js instead of InputfieldFile.js! So edit the latter, minify it and load it up to wire/modules/Inputfield/InputfieldFile/ . I would consider this a bug, as the system installed without any warnings or error messages - and doesn't work. cheerio Dominik