Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/31/2014 in all areas

  1. If you add temporary code, to delete certain pages, to the templates/admin.php: remember to remove it afterwards to avoid headaches, facepalms and keep you healthy. Actually happened a couple times already, I'm getting older too.
    7 points
  2. PW should and would remove stale session files. In some cases this so-called garbage collection does not work, especially on Ubuntu servers. Adding a couple lines of PHP to config.php solves this problem for most people. more info here: https://processwire.com/talk/topic/5796-session-handler-database-do-not-delete-old-sessions/?p=56596
    5 points
  3. I found this the other day http://www.vagrantup.com/ and it's awesome to make a virtual machine with just one command vagrant up and have all you need to code with processwire.
    2 points
  4. Not sure if someone already have this, but I just wanted to share it, hoping someone improve it, maybe it's good for a function? It will split long list of pages first top to bottom, then left to right. columns are chosen by you. A | D | G B | E | H C | F | I $columns = 3; // choose number of columns $item = 0; // set counter to zero $num = $pages->count("parent=/branche/"); // use variable for total pages $itemsInColumn = intval($num / $columns); // calculate how many child-pages per column echo "total: ". $num . " | per column: " . $itemsInColumn . "<br />"; // this can be removed if you don't want echo "<div class='left'>"; // left is css: float left foreach($pages->find("parent=/branche/") as $child) { $item ++; // count for each child-page a plus one if($item > $itemsInColumn) { $item = 1; // set back to 1 if total is larger then total in column echo "</div>"; // then end div echo "<div class='left'>"; // and start new float left } echo "<a href='{$child->url}'>{$child->title}</a><br />"; // output my child-page } echo "</div><div class='clear'></div>"; // clear float, end div I know you all must have this, but I am really starting to be afraid asking so I found out by myself
    2 points
  5. The best one I ever did (many, many years ago) was to reformat a disc. I studiously backed up the contents to another drive and then reformatted the entire disc. I can't remember exactly what the point was when I remembered that the other drive was in fact just a partition of the same disc.....
    2 points
  6. Just wanted to mention it also here that all front-end login code posted mostly in this forum has one flaw. The problem is with the login throttle that once it's kicking in, you'll get an WireException thrown and interrupt your login as you will only see this error and nothing else. There's a thread where this was asked and the solution is to use a try/catch to perform the login, this way you can catch the error message and output it where you want it. Looks like this try { $u = $session->login($username, $password); if($u && $u->id){ // user logged in do something $session->redirect("/profil/"); } else { $errors .= "Login failed."; } } catch(WireException $e){ // in case of multiple false login (throttle login) $errors .= $e->getMessage(); // get the error message } There was a mention here https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?p=50501
    2 points
  7. This thread just helped me work out a pesky nav problem I was having on a site. Thank you all!!
    2 points
  8. Your head must be a puzzle right now. I have the feeling that you just skipped the basics, and are looking at random things, some even too complicated for starting. I don't want to tell you how you should learn, everyone has it's own way, but I feel that you're taking the longer and less exciting path. Just sayin'
    2 points
  9. I forget to check if it is current page. Just add || $p === $page to your if clause and it should work as expected: <?php foreach($pages->find("parent=/illustration, sort=sort") as $p) { if ($page->parents->has($p) || $p === $page) { $class = 'current'; } else { $class = ''; } echo "<li class='$class'><a href='{$p->url}'>{$p->title}</a></li>"; } I know that coding navigation is not the easiest job in the world if you are not experienced coder. I think we should have some more code snippets shipped with demo site or some kind of code snippets area on website. Or FAQ or Wiki...
    2 points
  10. Ajax Search 1.1.0 There was a request for a ajax live search. So I went and created a simple module. Added in 1.1.0 * added key support for browsing results with arrow down and up. * added escape key to close results. * added close results on click outside http://modules.proce...es/ajax-search/ From the readme: This module progressively enhances the search form to an ajax live search. It will perform a search like you would use the form normally, and returns the output of the search page. So the search will still work without js enabled. There's some basic styling attached to this module in the "styling-example". You can use it to get started. See readme in there. Setup the search.php So it works almost out of the box with the basic install profile of ProcessWire, you only need make a minor change to the search.php template file to only return the content part (results) on a ajax request. To get the ajax search only return the content, open search.php and change the output on the bottom to this: ... if(!$config->ajax) include("./head.inc"); echo $out; if(!$config->ajax) include("./foot.inc"); Module Settings It comes with some module options to define various settings regarding the search form. Following a list with the defaults. Minium length = 3 min length for starting ajax request Close button text = 'close' close button text ID of searchform = #search_form if you have a different search form id,class ID of input = #search_query if you have a different search input id,class Query name = 'q' this is the default param name as_query_url = '' if left blank the script will take the action of the form Any help testing this module is appreciated. If you have any questions or problems setting this up feel free to ask here. Also feel free to use this as a starting point for your own, or take out the script to implement it differently. It's quite simple and can be adapted really quickly.
    1 point
  11. A quick tutorial how to create file downloads using pages You will be able to create a new page using template "PDF" (or any you setup), upload a pdf file. You then can select this page using page fields, or links in Wysiwyg. The url will be to the page and NOT the file itself. This will allow to keep a readable permanent unique url (as you define it), unlike /site/assets/files/1239/download-1.pdf, and you'll be able to update/replace the uploaded file without worring about its filename. Further more the file will also have an id, the one of the page where it lives. Clicking those links will download or open the file (when target="_blank") like it would be a real file on server with a path like /downloads/project/yourfile.pdf. You'll be also able to use the "view" action directly in the page list tree to view the file. Further more you'll be able to esaily track downloads simply by adding a counter integer field to the template and increase it every time the page is viewed. Since the file is basicly a page. This all works very well and requires only minimal setup, no modules and best of it it works in the same way for multi-language fields: Just create the language alternative fields like "pdf, pdf_de, pdf_es" and it will work without modifying any code! Still with me? ok PW setup Download folder: Create a template "folder" or "download-folder" with only a title needed. Create pages in the root like /downloads/project/ using this template. Setup the template for the pdf files 1. Create a new template in PW. Name it pdf 2. Goto template -> URLs tab and set the URL end with slash to no. (So we can have /path/myfile.pdf as the URL) 3. Create a new custom file field, name it pdf. Set its maximal count to 1 under -> Details tab. 4. Add the pdf field created to the pdf template. Easy. 5. Create a new "pdf" page using the pdf template under a download folder you created earlier. 6. Give it the title and in the name field add ".pdf" to the end (could also leave as is) Template PHP file for the pdf files 1. Create the template file pdf.php in your /site/templates folder 2. add the following code: <?php // pdf.php if($page->pdf){ wireSendFile($page->pdf->filename); } Done. To see the options you have with PW's wireSendFile() you can also overwrite defaults <?php // pdf.php if($page->pdf){ $options = array( // boolean: halt program execution after file send 'exit' => true, // boolean|null: whether file should force download (null=let content-type header decide) 'forceDownload' => false, // string: filename you want the download to show on the user's computer, or blank to use existing. 'downloadFilename' => '', ); wireSendFile($page->pdf->filename, $options); } Simple and powerful isn't it? Try it out. Some thoughts advanced Create as many file types as you like. It might also be possible to use one "filedownload" template that isn't restricted to one field type but evaluate it when being output using $page->file->ext, or save the file extension to the page name after uploading using a hook. One last thing. You can add other meta fields or preview images to the template and use those to create lists or detail pages. It's all open to goodness. Again all without "coding" and third-party modules. Further more you can use the excellent TemplateDecorator to add icons per template and have a nice pdf icon for those pages. This as a base one could also easily create a simple admin page for mass uploading files in a simple manner, and create the pages for the files automaticly. ImagesManager work in the same way. Cheers
    1 point
  12. Never mind. Double-click on the second tab and they merge.
    1 point
  13. Here's a few things to play with - I am a relatively new Mac guy too and the first few keep me sane http://binarynights.com/forklift/ and/or http://www.trankynam.com/xtrafinder/ if you can't stand folders mixed in with files alphabetically) http://hyperdock.bahoom.de/ http://stclairsoft.com/DefaultFolderX/ http://www.alfredapp.com/ http://justgetflux.com/ http://jumpcut.sourceforge.net/ (might be a newer alternative, but I use this all day long) http://www.mirovideoconverter.com/ (not Mac specific, but so convenient and easy) http://www.boastr.net/ http://www.vienna-rss.org/
    1 point
  14. lol, If you remove data with javascript, you should not search why PHP is not outputting
    1 point
  15. I guess it doesn't like the #t=134 Too bad you can't pass the start time though. I tried some of the other formats: &t=1m34s etc, but these must get stripped by the forum because they don't work.
    1 point
  16. try { paste https://www.youtube.com/watch?v=Wf68FTYoGKQ#t=134 . "\n"; } catch (Exception $e) { echo 'Exception: ', $e->getMessage(), "\n"; // doesn't work with this URL } http://www.youtube.com/watch?v=Wf68FTYoGKQ#t=134
    1 point
  17. I'm addicted to Jacco Gardner while designing (yep, not programming that much in the past weeks, and I miss it already) http://grooveshark.com/#!/album/Cabinet+Of+Curiosities+2013/8901053 Just paste the URL
    1 point
  18. Thanks! I followed the tutorial from their site during the weekend and am very impressed! Very easy to start and to work with
    1 point
  19. Logout need a refresh/redirect to reset session and user. https://processwire.com/talk/topic/1559-login-big-problem/?p=14153
    1 point
  20. Are you adding markup inside the render function in the class directly? That's how I'm reading it from your post above. All of that should be done in the /site/templates/ file for the relevant page template. This tutorial will help you understand rather than picking apart something more complex: https://processwire.com/talk/topic/693-small-project-walkthrough-planets/
    1 point
  21. Go on then! Currently I'd use Batcher or CSV Import to do that. You way sounds much quicker.
    1 point
  22. You're right, I'm just oversaturating a little. Post title doesn't say anything. Collecting children does a little more, but we do that all the time (I got two) Well there's sometimes a lot more than just how to, it's the what and where and why that may make a difference.
    1 point
  23. Thanks for sharing this. Seems to work on top of virtual box that I used in the past for disposable wamp servers. Will give it a try to see how it speeds up virtual box use.
    1 point
  24. This is an excerpt from an ongoing larger work that I am playing with so has a couple of references to things you haven't read - but it might be useful anyway. I notice that some new PW users are a bit confused about how they should structure their site within the /site/templates/ directory, so this is just some general waffle addressing that confusion rather than telling you what to do. Structuring Your SiteHere is a question that comes up in the forum more times than just about anything else: “I need to build a site that will have this bit as part of that bit and will need to have something over there while the bit under here relates to the image that isn't there and the entire lot needs to be static html….” What underlies the question and all its variant cousins is: “Is there a set way to structure the files for my site?” No. To be honest I am pretty tempted to finish this chapter here because that one little word really does sum up the entire point about ProcessWire, PHP, MySQL, Apache, JQuery and anything else that makes this system tick. None of it, including ProcessWire, is about how you want to structurally create your website; they are all tools that enable you to construct your site how you wish. Part of the problem, it seems, lies in the various demos and profiles that sdemonstrate how ProcessWire works and what it does. The very fact that they exist at all means that someone had to build them, and to do that, they had to structure them ... obviously. Developers and designers that have come to PW from other content management systems and who are used to having to follow fairly limiting guidelines automatically assume that the demo they are looking at represents how they MUST put the site together. Then they look at a different demo by another plonker and it is built in a completely different way. Bugger. The PW Templating System Most content management systems have a templating system of some sort or another. Sometimes it is based on a third party markup system, sometimes it is based around the idea of a huge amount of files that if you want to change you have to build overrides and put them in certain directories and then work out how to strip out all the ccs that is still in there. Some of them, particularly the ones that go on about CCK (Content Construction Kit, whoever that is) allow you a ton of versatility as long as you don’t mind that all the fields come complete with huge amounts of pointless nested DIVs and CSS referenced from one of the moons of Mars. Some have had this amazing idea that it is somehow really clever to separate the idea of an overall theme from the way components are laid out and therefore put them in completely unrelated parts of the file structure (some in the core that will be rendered useless at the next update). Anyone used Magento? The joke here is, of course, that none of this is about what a CMS is meant to do, it is about how to display the OUTPUT of a CMS, but somewhere down the line the two have got confused and the Content Management part of the system is now telling the public website part of the system how to do its job. And that brings me neatly to the ProcessWire Templating System. Which doesn’t exist. PW is a true CMS in that it gives you two layers of tools: Firstly it provides a way of storing, managing and processing data. Secondly, it provides an API that allows you to retrieve and manipulate that data. The bit it doesn't do is build your website for your – you are the designer or developer, you are probably the best tool for that job! There are a few rules … well, there is one rule actually, which we covered earlier: template files must have a php suffix and be kept in the templates directory. So, whether you construct your site using header and footer files included into your main templates, or whether you use a delegated approach or just one core template that you use to drag in markup from other files, or whether you use the API directly into a template, or as part of a php function or stored in a separate file, or whether you use jquery, ajax, JavaScript or anything else, this is all up to you and is NOT part of the PW system. It is back to how we started (in the main tutorial) with just one line of PW markup in an empty PHP file. <?php echo $page->title; ?> Now throughout this tutorial I will probably stick to some pretty basic construction – I will tend to use the API and PHP directly into a template file and possibly use an included header and footer just to reduce the amount of markup kicking around. However, this is not necessarily the best way of creating a website in PHP and PW, it is just a nice clear way; that is all. The PW forums have all kinds of discussions on different approaches for using PW and PHP and files and so do forums and blogs all over the web. The very fact that PW does not rely on one particular way to construct a website means that all those ideas from all over the place are perfectly valid and can probably be used in PW. Freedom is a wonderful thing, and so is a proper CMS. Joss
    1 point
  25. You can use selectors as you would use to retrieve pages. Only in this case you need to use the parameters that the current field contains. You can always do a var_dump on a certain object to see what parameters and variables it holds. echo "<pre>"; $key = 1; echo "1) ". $fields->get($key)->name ."\n"; // key = 1 echo "2) ". $fields->get("id=1")->name ."\n"; // selector: id=1 echo "3) ". $fields->get("name=title")->label ."\n"; // selector: name=title echo "4) ". $fields->get("name=title")->type ."\n";// selector: name=title $field = $fields->get(1); $field->set("label","Enter a title"); // key: label, value: Enter a title echo "5) ". $fields->get("name=title")->label ."\n";// selector: name=title var_dump($fields->get("id=1")); 1) title 2) title 3) Title 4) FieldtypePageTitle 5) Enter a title object(Field)[159] protected 'settings' => array (size=5) 'id' => int 1 'type' => object(FieldtypePageTitle)[133] private 'allowTextFormatters' (FieldtypeText) => boolean true protected 'data' => array (size=0) empty protected 'useFuel' => boolean true private 'className' (Wire) => string 'FieldtypePageTitle' (length=18) protected 'localHooks' => array (size=0) empty protected 'trackChanges' => boolean false private 'changes' (Wire) => array (size=0) empty 'flags' => int 13 'name' => string 'title' (length=5) 'label' => string 'Title' (length=5) protected 'prevTable' => null protected 'prevFieldtype' => null protected 'data' => array (size=4) 'required' => int 1 'textformatters' => array (size=1) 0 => string 'TextformatterEntities' (length=21) 'size' => int 0 'maxlength' => int 255 protected 'useFuel' => boolean true private 'className' (Wire) => string '' (length=0) protected 'localHooks' => array (size=0) empty protected 'trackChanges' => boolean true private 'changes' (Wire) => array (size=0) empty (string) $field; see type casting -> www.php.net/manual/en/language.types.type-juggling.php
    1 point
  26. To be honest, and no offense intended to the author of that module, but I don't believe it is really stable yet and unfortunately he hasn't been responsive to fixing some of the issues. The other issue is that it includes a lot of fields that you may not use. I think you'd be much better off creating your own system for front-end user management - it is very easy. This post from Ryan should get you started: https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?p=15919
    1 point
  27. // Add Antti as **the only** author for all the books written by Stephen King foreach($books as $b) { $b->author->removeAll() $b->author->add($ap); $b->save(); }
    1 point
  28. // Bookstore examples // Find all books that are priced over 30 dollars and set them on sale $overpricedBooks = $pages->find("template=book, price>30"); foreach($overpricedBooks as $b) { $b->title .= " *SALE*"; $b->price = $b->price - 10; $b->save(); } // Find author $sk = $pages->find("template=author, title=Stephen King"); // Find all books written by that author $books = $pages->find("template=book, author=$sk"); // create new author $ap = new Page(); $ap->parent = $pages->get("/authors/"); $ap->template = "author"; $ap->title = "Antti Peisa"; $ap->save(); // Add Antti as a second author for all the books written by Stephen King (continues from earlier example) foreach($books as $b) { $b->author->add($ap); $b->save(); }
    1 point
  29. I wonder if your day-to-day computer is like mine - stuffed to the brim with software that I tried once, forgot what it was and never got round to uninstalling it. I sometimes through my lists and think "I wonder what that did?" I also have a downloads full of mystery zips - I definitely downloaded them for something at sometime, but cant remember what. This is not helped that I have managed to keep a lot of my archives going from the mid nineties - some of those bits and pieces are probably freebees from the front of mags that are for windows 3.11 ..... Pity my memory is not quite as good.
    1 point
  30. You'll want to make sure that your Apache user has read, write and execute permissions to assets and it's subfolders. Other directories you rarely need to worry about. Setting permission 777 to whole assets directory recursively (chmod -R 777 site/assets/) is more than enough. You could be more specific and only allow it to only write into assets/files/, assets/cache/, assets/logs/ and assets/sessions/, but then there are modules that write directly to assets folder and would fail after this. Bad Gateway 502 as a result of this sounds like some strange server setting -- I've seen shared hosts throw errors if a file is executable/writable by all users (security feature attempting to mitigate risks usually caused by shared hosting itself, kind of ridiculous really), so this could possibly be something like that. In those cases you'll need to configure permissions properly: only give write and execute permissions to the user Apache is running as (often that would be your own user account). The host most likely explains this stuff somewhere. Apart from that I've no idea what could be causing that.
    1 point
  31. Just to make it myself more clear I installed skyscapers in another localhost folder - and it almost make more sence to me. Regarding the _out.php file, does this code mean the url is set to root and just append the hardcoded text cities after it? Where does it get the / from the browser url just after the root? <li><a id='topnav_cities' href='<?php echo $config->urls->root; ?>cities/'>Cities</a></li> It then goes to cities.php include("./browse.php"); and as it says include browse.php $headline = "Skyscraper " . $page->title; $browserTitle = $headline; $content = $page->children("limit=100")->render(); The first two lines are obvious to me, but the third one is a question... how is the sytem knowing it need to collect cities pages - in this case? Is this because of $page represents "cities" from the url in _out.php? Seeing how this Skyscrapers is working I guess I have to make seperate template files for each entry: jobs - province // in admin template with fields: - city - company - branche - skill jobs - city // in admin template with fields: - province - company - branche - skill jobs - branche // in admin template with fields: - province - city - company - skill
    1 point
  32. Antti, I'm really looking forward to that new Afghan Whigs record. Although, Rick McCollum (guitar) isn't on the record, so I have a feeling that Dulli wrote all the songs and it will sound like a Twilight Singers album. Nothing wrong with that, but it won't be the same without Rick. TEPPO!!!!! *Shakes fist at the sky* I finally managed to get that song out of my head, and what do you do? https://www.youtube.com/watch?v=nPv607Z57sE New (American) Krautrock.
    1 point
  33. Thank you, Wanze! I think I got it in a way. I was afraid no one would reply such a noob question. But you guys are so responsive, you rock Sometimes, even a tiny little thing would not make a sense and you have to ask someone else who knows. Such a welcoming community. I'll explore PW more and will make this website. Thanks again.
    1 point
  34. ProcessWire2.+ Minify 1.0.3 This module helps you combine Javascript and CSS files into one, minified file to save on unnecessary HTTP requests and to compress files anywhere up to 80% (including already minified .js files). To use it, extract the attached zip file into your /site/modules/ directory and check for new modules in the ProcessWire Admin area, then install the module. Once installed, go to configure the module and, instead of this configuring anything for you, you can use the drop-down lists to build stylesheet and script code to place in your templates, grabbing a list of any stylesheets and scripts it finds in the /site/template/styles/ and /site/templates/scripts/ directories respectively. It's more of a helper than anything else, but it should take the guesswork out of configuring Minify for your site. Notes: This module contains a third-party library - Minify - which is subject to its own license (a copy is included in the attached zip file). I've left the module in-tact including its unit test files so there are more files than are necessary, but this will make it easier for me to upgrade the module if/when they release updates to that code. This module doesn't insert any code into your templates automatically - I think copying and pasting the code it currently outputs to the screen is more useful/configurable for more situations. It's worth using even if you only have one CSS or JS file as it will compress CSS files by about 80% and JS files by quite a lot too, plus since it handles caching on the server-side and does its own checks of the files it is serving (plus it's a dynamic URL), you can always be sure that it will serve the latest version of a CSS file (no more CTRL+F5 to show the new styles if your browser decides to cache it. You can change the /site/modules/Minify/min/config.php as you could if you were using Minify as a standalone script - tweak cache paths (default is your server's cache path) and other advanced settings here. Updates: v0.0.2 - now produces code that includes paths derived by ProcessWire at run-time so paths will be fine on localhost and live servers, removing potential issues when pushing a site live. v1.0.0 - bumped this up to a major version number since there appear to be no issues with the initial versions to speak of. Also implemented yellowled's input field suggestion (looks much better and easier to select for copy and paste purposes) and turned off autoload at ryan's suggestion. v1.0.1 - now recusrively searches for files inside subfolders under the scripts and styles directories using PHP 5's built-in iterator classes v1.0.2 - pull request from teppo - https://github.com/Notanotherdotcom/Minify/pull/1 v1.0.3 - updated Minify code to v2.1.7 which fixes a significant security flaw: https://groups.google.com/forum/#!msg/minify/cpN-ncKPFZE/kwYVpLMkfDwJ You can download the module here.
    1 point
  35. I've built a processwire website for a friend and had lots of problems with "this request was aborted because it appears to be forged" after putting it on the production server. Now, after some weeks of searching for the problem (also at the provider...) solution was very simple and I like to share: The Webspace on the server was full. And cause every visit creates a session (inside assets/sessions/ folder) no new session could be created (new sessions files were created, but size was zero). The result was the "forged" message. So perhaps this could be one more solution, if anyone else has this problem...
    1 point
  36. Ohh I just got an idea for a module. What if you have a gallery type page you upload the images as usual to an images field. Then when saving the page there would be children created for each image and the ones removed from the gallery page. This would be very simple few lines of code. Sorry to hijack your thread. Nothing against the method to have one images field you store a gallery. If theres no metadata needed with no multilang and so on it is a pretty good and simple way to a simple gallery. I use it myself too.
    1 point
  37. The reason I like these kind of snippets so much is the freedom they offer. If you want to show the dev page to anyone that is logged in, change the conditional to: if($user->name='guest') If you want to give a special url like domain.com/?version=dev change it to: if($input->get->version!='dev') with the url version you can also make all the links work wth sessions like this: if($input->get->version!='dev' OR $session->version != 'dev') and inside the else: $session->version = 'dev';
    1 point
  38. Martin: thanks and glad that I could help. slkrwrm: I splitted your question to new topic: http://processwire.com/talk/index.php/topic,335.0.html
    1 point
  39. Sir, you are a gentleman. Thank you. I would not have worked that out. Regards Martin
    1 point
  40. Now that I looked your example I am pretty sure this is what you want (I also edited my previous example a little): <?php foreach($pages->find("parent=/illustration, sort=sort") as $p) { if ($page->parents->has($p)) { $class = 'current'; } else { $class = ''; } echo "<li class='$class'><a href='{$p->url}'>{$p->title}</a></li>"; }
    1 point
  41. If I understand correctly, I think this is what you are looking for: http://processwire.com/talk/index.php/topic,128.msg790.html#msg790 Based on what you've indicated, you'll want to change two things: 1. Currently it's applying the class "on_page" or "on_parent" to the <a> tag rather than the <li> tag. You mentioned you want it on the <li> tag, so you'd move the $class variable from the <a> tag to the <li> tag (which is just 3 characters before it). 2. Since you want the class name to be "current", you'd replace the "on_page" and "on_parent" class names hard coded in there to be "current".
    1 point
  42. stillmovingdesign: If you want to check if any page is one of the pages in path, you can use this code: <?php if ($page->parents->has($p)) { // This means that page $p is one of the parents of current page ($page) } In your example something like this: <?php foreach($pages->find("parent=/illustration, sort=sort") as $p) { if ($page->parents->has($p)) { $class = 'current'; } else { $class = ''; } echo "<li class='$class'><a href='{$p->url}'>{$p->title}</a></li>"; }
    1 point
  43. I've made a three level menu using this code, it's simple but it works. It highlights every selected level. Change the variables to fit your own or use mine, whatever suits you. <?php echo "<ul>"; $rootPage = wire('pages')->get('/'); foreach($rootPage->children as $menu) { $rootclass = $menu === $page->rootParent ? " class='current'" : ''; echo "<li$rootclass><a href='{$menu->url}'>{$menu->title}</a>"; if($menu->numChildren > 0) { echo "<ul>"; foreach($menu->children as $child) { $class = $child === $page ? " class='current'" : ''; echo "<li$class><a href='{$child->url}'>{$child->title}</a>"; if($child->numChildren > 0) { echo "<ul>"; foreach($child->children as $grandchild) { $subclass = $grandchild === $page ? " class='current'" : ''; echo "<li$subclass><a href='{$grandchild->url}'>{$grandchild->title}</a></li>"; } echo "</ul>"; } echo "</li>"; } echo "</ul>"; } echo "</li>"; } echo "</ul>"; ?>
    1 point
  44. If understood right, you need to change $page->rootParent to $page and everything will work You get this: <?php foreach($children as $child) { $current = $child === $page ? " class='current'" : ''; echo "<li$current><a href='{$child->url}'>{$child->title}</a></li>"; } // adamkiss: added '<?php' in your block to force code coloring
    1 point
×
×
  • Create New...