-
Posts
6,808 -
Joined
-
Last visited
-
Days Won
159
Everything posted by Soma
-
You dont need all of these checks, the code I posted aleeady takes care of it.
-
What funny title.. I lol'd. It should be "WP got hacked need PW 2.0". I almost got a heart attack.
-
Nobody? Ok, since the tags introduced to the image field is just a plain text field, there's no other way than to loop all pages that have images loop all images to grab all tags, parse them to array and merge them. This gets you there but doesn't scale well. (Would those tags be page relations it would make it very easy to output all tags. I'm more of a fan of using page fields for tagging, but there's no image field with page tags and I use different image system if there's a lot of images with tagging and galleries. My ImageManager is one of the tools to have a page as image and you can attach as many fields to the image template to get those things done.) I often thought about what would be the best ways, with words in text fields all over the site, to collect them and I think you have two possibilities. Raw SQL query, or the above loop all pages and make that a markup cached snippet, if the amount and time to generate the list takes long, that runs every other day or hour. Also have as many restrictions, for template or parent, as you can get to make the query a little more efficient. To show what would be the API way you already got a good start and intuition with 2 foreach. The following collects all tags and makes a unique array to create a link list. EDIT: You can use url segments or GET parameter for the links. Since PW urls doesn't allow special chars there's a workaround inside the code now. /** * collect all tags * ====================================== */ $alltags = array(); // container $use_urlsegments = false; // find all pages that have images with tags $parray = $pages->find("template=basic-page|gallery, images.tags!=''"); // loop pages found and collect tags from images foreach($parray as $p) { // find all images that have no empty tags, yeah you can // also use find on Pagefiles array! $images = $p->images->find("tags!=''"); // loop them and add tags to array foreach($images as $im) { $tags = $im->tags; // convert "," and "|" to space and create array using explode if(strpos($tags, ',') !== false) $tags = str_replace(',', ' ', $tags); if(strpos($tags, '|') !== false) $tags = str_replace('|', ' ', $tags); $tags = explode(' ', $tags); // convert tag value to a page name using beautifyer, ü => ue, ö => oe // since special chars are not allowed in PW urls foreach($tags as $tag) { $alltags[$sanitizer->pageName($tag, Sanitizer::translate)] = $tag; } } } /** * generate links with tags as urlsegment * ====================================== */ // make the array unique and create a tags nav from it // add tags to the url of the page to later read it and // render a list of pages echo "<ul>"; foreach(array_unique($alltags) as $key => $tag) { if($use_urlsegments) { echo "<li><a href='{$page->url}$key'>$tag</a></li>"; } else { echo "<li><a href='{$page->url}?tag=$tag'>$tag</a></li>"; } } echo "</ul>"; /** * find all pages with the supplied tag * ====================================== */ // enable url segments on the template if using url segments if($input->urlSegment1 || $input->get->tag){ if($input->urlSegment1) { $tagvalue = $input->urlSegment1; // get the original tag value text from the cached array $tagvalue = $alltags[$tagvalue]; } if($input->get->tag) { $tagvalue = $sanitizer->selectorValue($input->get->tag); } // find pages with images having the requested tag $pa = $pages->find("images.tags~='$tagvalue'"); if(count($pa)) { echo "<h2>Pages found</h2>"; echo "<ul>"; foreach($pa as $p) echo "<li><a href='$p->url'>$p->title</a></li>"; echo "</ul>"; } } What was the other question again? And of course also found in my ever growing gist archive https://gist.github.com/somatonic/5808897 I'm too lazy to brew a SQL that does the collecting part. But there's people more clever than me that can help.
-
Why does $page->rootParent identify current section?
Soma replied to isellsoap's topic in Getting Started
Well obviously the condition isn't met so it's always false. For me I'm still trying to figure out what the heck you're doing with belongs_to.. seems redundant to me but maybe because I don't get it.- 16 replies
-
- current section
- semantics
-
(and 2 more)
Tagged with:
-
@k Without knowing further details/context, why not just build your own menu? It can be as simple as $menu = "<ul>"; foreach($pages->get("/sompath/")->children as $child) { $menu .= "<li><a href='#'>$child->title</a>"; if($child->numChildren) { $menu .= "<ul>"; foreach($child->children as $subchild) { $menu .= "<li><a href='#{$child->name}-{$subchild->name}'>$subchild->title</a></li>"; } $menu .= "</ul>"; } $menu .= "</li>"; } $menu .= "</ul>"; echo $menu; If you still want to go the module way, yes there you could make a hook to archive what you want. There's a couple examples in this thread, but there can't be enough I guess function hookTagsString($event){ $child = $event->arguments("page"); if($child->template == "form"){ // some check for template? as you like // now return your own link markup with $event->return $event->return = "<a href='#{$child->parent->name}-{$child->name}'>-$child->title</a>"; } } $nav->addHookAfter("getTagsString", null,'hookTagsString'); // render the navigation echo $nav->render(null, null, $pages->get("/somepath/"));
-
There seems to be a flood of tweets from the previous and there's a new "review" http://wpdaily.co/processwire/
-
You found the right one!
-
This can get really creative, as Ryan would now maybe come with something like: $nav = ''; foreach(array("prev","next") as $dir) { if($page->$dir->id) $nav .= "<a href='{$page->$dir->url}'>$dir</a> | "; else $nav .= "<span class='inactive'>$dir</span> | "; } echo trim($nav, " | ");
-
You need a timestamp!
-
There's an easy way to strip off chars with php method trim(). But in this case it can get tricky. Also regarding PageArray and explode doesn't really play a role here... But it sinks in better if you make faults. I think an idea would be to do: $nav = ''; if($page->prev->id) $nav .= "<a href='{$page->prev->url}'>prev</a> | "; if($page->next->id) $nav .= "<a href='{$page->next->url}'>next</a> | "; echo trim($nav," | "); Fairly easy concept. Depending on how and where you use it, this way it can get annoying as you get jumping link elements. You get sometimes "prev" sometimes "prev|next" links So maybe add some logic to show only a span when there's no next found. So you can fade it out with CSS. Now this way there's no need to trim. $nav = ''; if($page->prev->id) $nav .= "<a href='{$page->prev->url}'>prev</a> | "; else $nav .= "<span class='inactive'>prev</span> | "; if($page->next->id) $nav .= "<a href='{$page->next->url}'>next</a>"; else $nav .= "<span class='inactive'>next</span>"; echo $nav;
-
Why is ProcessPageAdd::execute() method hookable?
Soma replied to pogidude's topic in General Support
Well no reason behind I think, all core Process modules execute() are hookable whether useful or not. I this case you could replace the add form with your own, what else But to be honest it would be better if buildForm() would be hookable, but nobody needed it so far so it's not. The thing is the execute() returns the form rendered already so you can't manipulate it using OOP. -
Every find will return a PageArray already, no need to explode to get the page id as array you already got them... My guess is that most people try to echo $p, and see that there's something like "1002|1230|2130" ... but that's not what's really behind $p and seems a common misunderstanding of non-coders. It's the magic toString() method of PageArray that returns the id's in that way. See https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/PageArray.php#L407. So what you trying to do an extra step to explode something that PW implodes. This stringification is handy if you want to use the result $p in a selector. "id!=$p" will result in "id!=1002|1230|2130". But in your case you already have an PageArray and simply can loop the pages inside $p. $p = $pages->find("images.tags~=$tag") foreach($p as $onepage) { echo $onepage->title; }
-
It's the famous "how to do this" question.
-
Maybe this is also interesting https://github.com/mexitek/phpColors
-
Ryan the localUrl doesnt work if theres 404 thrown for a url. When you call a url that doesnt exist it will stay at that url and renders the 404 page. There it fails because something with the page names language module doesnt have a language set or something I cant remember. I think its maybe also only if not default language or the user has alternative language set. Try that changing user language and see.
-
If you leave outer tpl empty you should still specify the "||" .. 'outer_tpl' => '||'
-
This method is different from what we normally use for select options. As you can guess from the responses, we use page fields to build selects and the options are actual pages. http://processwire.com/videos/page-fieldtype/ This allows for much more flexible and dynamic building as the options are coming from pages. The select field you're using is completely different as you have options hardcoded into the field, you could just hardcode the labels in your template too. You know which key has which value. Or to make things simpler you could use the inputfield interface of the select field to get the options.. $options = $fields->selectfieldname->getInputfield($page)->getOptions(); echo $options[$page->selectfieldname];
-
Is it possible you don't use a page field, but the custom select field like http://modules.processwire.com/modules/fieldtype-select/?
-
Just wanted to let you all know, I updated the module to 1.1.9 , with another new hook method to manipulate or add your very special case classes that will get added to list_tpl's "%s". To use this, here a little example to make it clearer. I want to add a class to my page with id 1001. Ok here we go. $nav = $modules->get("MarkupSimpleNavigation"); function hookGetListClass(HookEvent $event){ $child = $event->arguments('page'); // current rendered page item (in naviation) $class = $event->arguments('class'); // the class string, may be empty or filled if($child->id == 1001){ // add your checks, use API or whatever... daytime... $event->return .= " yourclass"; // add your class names } } $nav->addHookAfter('getListClass', null, 'hookGetListClass'); echo $nav->render(); Added this to readme
-
In PW 2.3 all jQuery traversing methods are available. So not yet in the cheatsheet is things like prevAll(selector) or nextAll(selector), nextUntil(selector) ... For what you ask I think this is what you need: $found = $page->siblings("template=mytemplate,body*=your text")->first(); if($found->id) { echo $found->body; } Nothing to explain really, except that sibling() is like find() and returns an PageArray of pages even if only one found. So to get the first from the array you add ->first. This will return on the one page and you can make sure it has one found with if($found->id){... Edit: ok maybe another one on a sidenote, when working with $page->siblings(), it will also return all including the page you're calling this from. So you could add a selector "id!=$page->id" to exclude it.
-
It was updated 4 hours ago... Yes there's a readme with examples...
-
Have you got the latest version? https://github.com/ryancramerdesign/MarkupTwitterFeed Ryan has done some updates today/yesterday
-
Little detail. Instead of $p->setOutputFormatting(false); you can also use $p->of(false);
-
I still have no idea what you want to target and how you imagine doing it... So I can't help. I know what a child of a parent is, but it's not something I can get a hand on in a navigation, it's nothing specific or I just don't get it. Maybe this is something you can use: "list_field_class" => {template} p_{id} or "list_field_class" => p_{name}
-
I have trouble understanding what you want and why? A child of a parent?