Jump to content

bwakad

Members
  • Posts

    450
  • Joined

  • Last visited

Everything posted by bwakad

  1. I have this function to limit words from body field in list view function limit_words($string, $word_limit) { $words = explode(" ",$string); return implode(" ",array_splice($words,0,$word_limit)); } # declare field for limit output $intro = limit_words($page->body,20); then I call child pages though my template file with this: foreach($pages->find("parent=/all/") as $child) { echo "<a href='{$child->url}'>{$child->title}</a>"; echo $child->$intro; echo $child->intro // is obvious, just displays full text echo $child->$intro // produces nothing echo $intro // does nothing Maybe I'm simply not seeing it clear at the moment - so if anyone knows, please give a tip...
  2. I see in includes/navigation.php the following code. The code in bold is my problem. In the menu - I want the parent page to be visible and clickable, but not it's childs of this menu item. My page tree is root - menu item - - child 1 - - child 2 childs can be more then 30 so it's not good to see those in the menu. edit - the bold get's removed when using code tags... I was talking about this piece: if($has_children && $child !== $root) { $class .= 'has-dropdown'; // sub level Foundation dropdown li class $childUrl = "#"; // stop parents being clickable } else { function renderChildrenOf($pa, $root = null, $output = '', $level = 0) { if(!$root) $root = wire("pages")->get(1); $output = ''; $level++; foreach($pa as $child) { $class = ''; $has_children = count($child->children) ? true : false; if($has_children && $child !== $root) { $class .= 'has-dropdown'; // sub level Foundation dropdown li class $childUrl = "#"; // stop parents being clickable } else { $childUrl = $child->url; // if does not have children, then get the page url } // make the current page and only its first level parent have an active class if($child === wire("page")){ $class .= ' active'; } else if($level == 1 && $child !== $root){ if($child === wire("page")->rootParent || wire("page")->parents->has($child)){ $class .= ' active'; } } $class = strlen($class) ? " class='".trim($class)."'" : ''; $output .= "<li$class><a href='$childUrl'>$child->title</a>"; // If this child is itself a parent and not the root page, then render its children in their own menu too... if($has_children && $child !== $root) { $output .= renderChildrenOf($child->children, $root, $output, $level); } $output .= '</li>'; } $outerclass = ($level == 1) ? "left" : 'dropdown'; return "<ul class='$outerclass'>$output</ul>"; } // bundle up the first level pages and prepend the root home page $root = $pages->get(1); $pa = $root->children; $pa = $pa->prepend($root); // Set the ball rolling... echo renderChildrenOf($pa);
  3. @teppo I was actually looking for a box like you can find on fields description. Would be nice to have that in the back-end for page/template/field. Where you can directly edit the notes on the fly. But soma's mod will do for now.
  4. Great! thanks for the link. Must look in my module manager more often...
  5. It's a funny topic title I know - nothing implied by it ;-) But I was reading about Joss's foundation site profile AND soma's Delegate approuch for templates. Since I liked both, I ended up mixing it. And it's been fun so far. The foundation profile is simple and understandable, but I did remove the orbit - just don't like slide shows... The way from Soma is basically 1 template file: main.php - where I placed the code (from soma). In the back-end I just created the templates (without file) I need for different views. On the server I then created the view folder with .php files. And upon creating a page I select the back-end template (without file). And use alternate name in back-end template e.g. main (without .php) The code then looks up the .php file in the view folder. Once I did it like this, I can see much more possibilities, navigation becomes more easy (in depth), and relationships between pages and fields is more easy this way. So thank you both!
  6. Does anyone know if this excists in the back-end? notes by admin? example: in edit screen of template / page : custom box for notes, 'used for this', 'links to that'...
  7. You all explained very good. I think sometimes I still have issues thinking other CMS wise... Have to forget about limited CMS's, and start thinking PW ;-) So I will close this topic as answered.
  8. thanks, I will use both in different conditions!
  9. Is there something available that can limit the characters or preferably words from a field in a template for a list. Or do I have to make 2 fields, one for intro and one for full text, which would not be convenient. Example: List view (index) item one - myfield (20 words) item two - myfield (20 words) Full view (item) my field - full-text Could not really find anything
  10. Thinking in other CMS, pages were created for displaying your content. But, since I started with PW, I see pages can be created for anything. Including selects. And I had the impression for PW - selects - could only be made by - page field type, and selecting the pages by selector. But then I also downloaded Select AKA dropdown - where you just have to fill in the label/value. I would like to know what is more appropiate to make a select list, what is beneficial about it.
  11. I don't know exactly where I read it, but it was saying that find() is less heavy as get(). Then I also notice some people are able to tell what is heavier for server requests. Now, looking at my selector - which fetch all children of children - I would like to know how you can tell if this is good practise, considering speed and request. And by what program you can tell. $myparent = $pages->find("parent=/province/"); foreach ($pages->find("parent=$myparent") as $value) { echo $value->title; }
  12. in my case I had the same problem until I used parent=page.province and I was able to save... but I am just guesing, really don't know so much yet
  13. 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
  14. I know I know... I just wanted to see how it works. But you are right. I think markup should be in the template file rather then through render. So it's easier to read. So I just deleted all files, emptied DB, and started on a fresh dev install (no site profile other then basic one). Made some pages and some loops to get a list in my template file. And since this list becomes veryyyyyy long I really need a css to attach, like bootstrap (easy) or foundation (litle hard). I just don't want all the files like site-profile from http://processwire/modules gives because you all will tell me to start with a fresh install again. lol
  15. So today I learned about render, retrieving fields / pages and selectors in general. I have to admit, many times I do not know, often I look at Skyscrapers to see some interesting stuff, read the API and see the the forum where many guru's are active. As such I learned some and added my own lines in the render function. // get field province, from current page, store in location $location = $page->get('province'); // use markup, get url and title of location, store in where $where.= "\n\t<li><a href='{$location->url}'>{$location->title}</a></li>"; // and then finally output 'where' plus it's markup, inside table $out = "\n<table class='blahblah'>" . "\n\t<tbody>" . "\n\t<tr><th>Province</th><td>" . ($where ? "\n<ul>$where</ul>" : $na) . "</td></tr>" . "\n\t</tbody>" . "\n</table>"; return $out;
  16. Sorry for the confusion ... to tell you the truth, since I started this topic, and solutions where diverse, I really had to think which answer I had to marked as Solved. I was talking about a drop down list - 400+ should not be to much problem server side, but maybe it's also not very usefull for client side. Thinking client side, I prefer having a dropdown (if applicable) and when using a tab (keyboard) you see the whole list, so I can use my up/down keys or alphabet key to choose... but that's just me. That's why I had to go with soma answer. I'm learning from you all !
  17. Well, I like to thank you all for thinking with me, but I have to say Soma was right. 400+ in a list on front end is not to good! But hey, at least I learned something... I will go for the sidebar and retrieve items from current page if any, so when I have a view of province, I get a list of cities.
  18. ok, I did not blame you Thinking what you said about speed an all, I was using the below code and looked in the API selectors. In my search form: the search form has <p> <label for='search_keywords'>Keywords</label> <input type='text' name='keywords' id='search_keywords' value='<?php if($input->whitelist->keywords) echo $sanitizer->entities($input->whitelist->keywords); ?>' /> </p> then it's send to the search.php where this part give me an error: if($input->get->keywords) { $value = $sanitizer->selectorValue($input->get->keywords); $selector .= "title|body|municipal%=$value, "; $summary["keywords"] = $sanitizer->entities($value); $input->whitelist('keywords', $value); } I understood that it searches all fields for the value. If I use: $selector .= "title|body%=$value, "; everything fine, no error, but no search on municipal either.
  19. Well, thanks for the effort anyway. ps. I thought I was clear on what I wanted to do - from the topic title and description in the first post - but maybe i'm thinking simple - and others think php
  20. In total there are 400 pages as childrens. I use this as list select on a search form to search by municipal. Meanwhile I was looking further in it and also noticed I can use the following code, but it will only give me the list of children under the first parent. foreach($pages->get("children=/location/")->children() as $municipal) { Perhaps if it is to heavy - which I think it is - the municipal is a field, so I better use this next code, change it a little to search in fields. That way it possibly does not need to go through all entries: // if there are keywords, look in the title and body fields for the words if($input->get->keywords) { $value = $sanitizer->selectorValue($input->get->keywords); $selector .= "title|body%=$value, "; $summary["keywords"] = $sanitizer->entities($value); $input->whitelist('keywords', $value); }
  21. I have this code which I need to rewrite to retrieve a list of children pages from the parent under location. location - parent01 - - child - - child - parent02 - - child - - child foreach($pages->get("/location/")->children() as $municipal) { I need to collect the childs. Is there something for this? Because I tried siblings() but that did no good. Or do I need to first make a foreach on the parent, and inside foreach for the children? - if so is that good practise?
  22. Basically what I found out from this Skyscrapers site profile that all 1st level templates (under the root) are set to have NO at Can this template be used for new pages? (except the basic-page). basic-page template (family-tab) says: YES at Can this template be used for new pages? basic-page at Allowed template(s) for children I think this is why at first you can only choose 1 template named basic-page when creating a new page right under the root. After the page is created, if I was not allowed to change settings as admin I would have to do this: 1. edit basic-page template 2. change allowed and save 3. edit page I created 4. change template for it and save 5. edit basic-page template 6. change back to original and save
  23. Although a default value for 1 single select works, it does not work on dynamic single selects. The only way I could solve this was to take out the default value for the first select. Then on the second select I used: Show this field only if province!='' On a new page where fields where not chosen, and on edit page where fields where added after creating the page: First field (province) shows blank and full width. And when choosing a value; second field (municipal) shows blank and full width. And in template files I don't have to worry about default value because fields are required before saving. Note! would be nice if developers just remove the default value at back-end to avoid confusion!
  24. Ahaaaa.... so render can be used to give output a different look if you wanted
×
×
  • Create New...