Jump to content

Search the Community

Showing results for tags 'pageArray'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Categories

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 34 results

  1. Hi, I have a page with a repeater called teams with two fields: team (a pageReference with a list of teams) and people (a pageReference with a list of people who likes this team). I'm trying to populate the people field in the repeater according to the value of the team field in the same repeater. So far. I'm able to get the pageArray that I want to assign to the people field, but i don't know how to "save" the value for each instance of the repeater. I hope somebody can give me a light. Thanks in advance. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'people') { $repeaterField = $event->arguments('page')->teams; foreach ($repeaterField as $t) { // Is this the way to loop the instances of the repeater? $team = $t->team->id; $t->people = $event->pages->find("template=user, team={$team}"); var_dump($t->people); // This returns the values that i want to assign for each repeate instance $event->return = $t->people; // I hope this assign a custom pageArray for each repeater, but it assigns the same for all the instances of the repeater } } });
  2. I can't add a new value to a custom PageArray field for my user. However, when I create a new user, I CAN add the new PageArray value: I need help. Thank you very much.
  3. I have a page field on my home template with output set to multiple pages (PageArray). I can echo its value, 1111|2222, or foreach $nav as $p echo $p, 11112222. But when I do this that I need to, it doesn't work: foreach ($mainnav as $p) { if($page->rootParent->id == $p->id) $current = 'style="background: #fff;"'; else $current = ''; echo "<a href='{$pages->get($p)->url}' $current class='{$pages->get($p)->name}'>" . strToUpper($pages->get($p)->name) . "</a>"; } I get: I've tried the conditional in the code with one and three = signs.
  4. Hello there! I'd love to see more array operation functions such as map/reduce. There are already a few helpful functions there like pop, shift, etc. I find myself turning pageArrays into arrays, do array_map or similar and create pageArrays again from that data. For Processwire, it would be really helpful to perform forEach operations more comfortably. E.g. <?php $allTitles = $pages->map(function($page){return $page->title}); // vs traditionally: $allTitles = []; foreach($pages as $page) { array_push($allTitles, $page->title); } $pages->reduce would be really helpful too. This would avoid many in-between variables when calculating sums of fields stored in individual pages. Thank you in advance Best, Martin
  5. Good Day! I am a beginer of processwire project. Thanks developers for your great work. this CMS is very Good! I have a question: how get Pageimage object of PageArray from "Page" (PageArray) field type? I have too tamplates: affiliates and their teachers. The template of affiliates have a field "teachers_list" wich is "Page" (PageArray) type. When I vaffiliate teachers in a cycle, I can not access the teacher photo object and change its size. I get an error returning: " Fatal error: Call to a member function maxWidth() on null ". When i trying get URL attribute : $teacherItem->teacher_photo->url, i receive message: " Trying to get property of non-object ". But this code works: $teacherItem->teacher_photo["url"]. The print_r function outputs the following information: "ProcessWire \ Pageimage Object ([changes] => Array ([0] => formatted) [hooks] => Array ([Pageimage :: pim2Load] => PageImageManipulator02-> getPageImageManipulator02 () in PageImageManipulator02.module ) [Data] => Array ([basename] => p16.jpg [description] => .... - ..... [tags] => [formatted] => 1 [modified] => 1487079115 [created ] => 1487079115))". my PHP code: foreach ($page->teacher_list as $teacherItem): $out .= " <tr> <td class=\"alignTop\"> /* !!! my truble */ <img src=\"{$teacherItem->teacher_photo->maxWidth(250)->url}\" /> /* !!! my truble */ </td> <td class=\"alignTop\"> <div class=\"teach_style12\"> <strong>$teacherItem->fio</strong><br/> $teacherItem->degree<br/> $teacherItem->headline_detail </div> <div class=\"teach_style9\"> $teacherItem->body </div> </td> </tr>"; endforeach; Please, help me. Where is my error?
  6. Hello everyone, i guess my php knowledge is not good enough to find a solution for the following problem: I'm building a website where i have projects. Each project has tags like "webdesign, responsive, cms, print, flyer" etc. At the end of a project i want to recommend other projects, which have similar tags. I want to limit the recommendations to three other projects sorted by the hightest amount of same tags. This is how far i got: I'm using <?php $interessantes = $pages->find("tags=$page->tags, id!=$page->id"); ?> to find other projects with the same tags, excluding the page i'm already on. Then i'm using three foreach-functions to go through the projects i found, the tags they have and compare them with the tags of the project i'm looking at. If i have two identical tags, i count up a variable. <?php // Projects i have found foreach($interessantes as $interessant): $i = 0; // Tags of the projects i have found foreach($interessant->tags as $tag): // Tags of the project i'm looking at foreach($page->tags as $tagreferenz): if($tag == $tagreferenz): $i++; endif; endforeach; endforeach; endforeach; ?> You can see what it looks like in the screenshot with a bit of HTML. I marked the tags of the current project green and the identical tags of other projects red with the amount of hits below. So in this example i would want to have three projects with three similar tags and get rid of those with only two and one. I guess i have to put my pages into an array (with the number of hits?), sort them and echo them with "limit=3"? Unfortunately i have no idea how to do this. You probably have an even better/shorter solution. Links to other topics are welcome to and i'll try to get my head around it. If you need further explanation, i'll try my best. Best regards
  7. I've got this code to fetch all pages: /** @var PageArray $pages */ $pages = $this ->wire('pages') ->find(sprintf( 'has_parent!=2,id!=2|7,status<%s', Page::statusTrash )); With this I fetch all pages except admin, but that includes the 404 page as well. Is there a way to exclude pages like the 404 page from the result? Or maybe loop through the result set to check for the pages response code (without curl that is)? I want to avoid filtering the 404 page by ID if possible.
  8. Hey, I've searched for this and I couldn't find it, what i want to do is check if a page (object) already is in a PageArray field? Ofcourse i can go through it with a loop but if theres already a method to do this then i dont want to re invent the wheel.
  9. I have a situation where a pagearray appears to lose its sort order. 1. template xyzzy.php fetches a pagearray with code similar to: // in an external include file function get_pages($selector) { $found = wire('pages')->find($selector); wire('log')->save('fubar', count($found)); return $found; } // in the template xyzzy $pa = get_pages($some_selector); $pa->sort('-timestamp'); 2. main.inc is appended to the template. in main.inc an additional file is included, './layouts/xyzzy.php' 3. './layouts/xyzzy.php' then references $pa as such: <? foreach($pa as $p): ?> // do stuff with $p // log for debugging wire('log')->save('xyzzy', $p->name); <? endforeach ?> 4. The $pa that './xyzzy.php' sees is sorted while the $pa that './layouts/xyzzy.php' sees is NOT sorted. It seems like the PageArray/WireArray got copied at some point but the './layouts/xyzzy.php' file shouldn't have been included until 'main.inc' is appended. What am I missing?
  10. I have several fields on a site I am working on and want to pull values from a multiselect field but all I get are the page_ids. Any help would be appreciated. Thanks.
  11. Hi, I have an array of Page IDs ($matches) which I'm using in a PageArray ($matches_limit): $matches_limit = $pages->find("id=$matches, limit=$page_limit"); This is working fine but I need to maintain the sort order of $matches, however $matches_limit reorders the $matches (I guess to sort=sort). Is it possible somehow to maintain the order $matches when outputted in the pagearray?
  12. Hello together, this might be a newbie questions, but I got some problems with a PageArray and don’t know how to go on. My goal is give out the parent.name of a page that was found earlier and was put into a PageArray. My found pages: $matches = $pages->find($selector); Some of the pages that are present in $matches need to be put into a new array $the_page_array. I do this via a this foreach loop, but I do not foreach($matches as $match) { if ($match==condition_blah_blah) { $the_page_array[]=$match; // if condition true, then add pages to new array } } From here, I can print out some stuff, e.g. my parent.name of the $single_page: foreach($the_page_array as $single_page) { echo „<a target='_blank' href='$single_page->url'>$single_page->title</a> "; echo $single_page>parent->name; } So far so good. But from here I want to find some pages in the PageArray that have a given parent.name: $filtered_matches = $the_page_array->find(„parent.name=blahblahblah"); But this gives out an error: Error: Call to a member function find() on array In fact, I can use any PageArray function like $filtered_matches = $plz_page->getTotal(); and I get the same error. I believe this has something to do that $the_page_array is an PageArray (or not)? Any help or hint would be wonderful. Thanks in advance Thomas
  13. Hi, Run into a bit of an issue with pagination on a site I am working on. I am sure the answer is really simple, but struggling to figure out what's going wrong. I have a bunch of articles, but I only want the ones where the date is less than the current date. I then want to limit the array so that I can paginate it. <?php $allNews = $page->children("template=news"); $oldNews = new PageArray(); foreach($allNews as $article) : if(strtotime($article->date) <= strtotime('now')): $oldNews->import($article); endif; endforeach; $oldNews = $oldNews->find('limit=2, sort=date'); echo $oldNews->renderPager(); foreach ($oldNews as $article) : ... endforeach; ?> The limit is being applied, however I don't see any pagination and navigation to the different pages returns the same first two articles. Any help would be much appreciated. Thanks, Craig
  14. I've poked around the forums and can't figure out the following: I have a page that uses a $pages->find to generate a pageArray called $test. I am then using $test->render(); to create a list of page links for returned results. When I click on one of the page links it takes me to the correct page (let's call it Page1). So far so good. Now, on Page1 I have some $page->prev and $page->next stuff going on. My problem is that it is creating links for direct siblings to Page1 based on PW's Page Tree and not my previous page's $test pageArray of links. I tried the following: $page->next($test); but this didn't work because I presume $test doesn't actually exist as part of Page1 (the pageArray was generated on the previous list page). I don't know how to make my initial pageArray pass through to subsequent pages and then have a prev / next nav that cycles through my pageArray results. Or am I thinking and going about this all wrong? Thanks.
  15. Hi there, I'm having trouble instantiating a PageArray and was wondering if i've overlooked something very obvious (Won't be the first time!) I've included a snippet of the code The Error I'm getting is "Class 'Site\PageArray' not found". I'm using namespaces as I've had name collisions before. Still stumbling my way through PHP and any guidance would be much appreciate. ---------------------------- G namespace Site; class Data { /** * Wrapper function to return items inside a PageArray. * @param $items * @return PageArray - A PageArray containing all the items passed in */ static function PageArrayWithChildren($items) { //$array = new wire(PageArray); $array = new PageArray(); foreach($items as $item) { $array->import($item->children()); } return $array; } }
  16. I want to create a basic breadcrumb menu on my site and i'm using this code <?php $parents = $page->parents(); ?> <?php foreach( $parents as $item): ?> <span><a href='<?php echo $item->url; ?>'><?php echo $item->title; ?></a></span> <?php endforeach; ?> <span><?php echo $page->title; ?></span> When i print_r $page->parents() it has the correct count and urls. But when i go to foreach it misses out a step. for example if i was on the curriculum page it should say: home > about us > curriculum but it just echo's out: home > curriculum Am i doing the foreach wrong? i followed the example code Ryan posted for making a breadcrumb menu.
  17. Hi. I need to compare two pagefields. I tried this: $page->locations->has($user->locations) But this doesn't work. I need to compare them and find out if the $page->locations has one or more of the same locations as the $user->locations. Hope it makes sense.
  18. I am having trouble working out the syntax for outputting relational data that is nested inside a repeater field. I only started using repeater fields a couple of days ago, and pagearray fields three weeks ago. The problem involves the following templates and fields: classlesson_plan_section (repeater field, containing the following)lesson_plan_time lesson_plan_subject lesson_plan_section_type (pagearray field) online_tools (pagearray field) lesson_plan_section_typetitle lesson_plan_section_description online_toolstitle url I have outputted the regular text areas of the repeater field fine, like this: *table beginning code snipped off* foreach($section as $item) { $lesson_list .= "<tr><td>" . $item->lesson_plan_time . "</td><td><p><strong>" . $item->lesson_plan_subject . "</strong><br> </td><td> </td></tr>"; } *table end code snipped off* I can get the repeater fields to output, and usually I can get pagearray fields to output, but I am having trouble now that the pagearray is inside a repeater field. Do I need to add the repeater field to my syntax? I mean like this: online_tools=$page->lesson_plan_section->online_tools I have been doing various, ridiculous things with my code to try to replace the '$nbsp;'s with the lesson_plan_section_description and online_tools pages selected in the repeater field, but without luck. I know I that before output, I have to find the pages like so: $section_type = $page->lesson_plan_section_type; $tools = $page->online_tools; $section_find = $pages->find("template=lesson_plan_section_type, lesson_plan_section_type=$page->lesson_plan_section_type"); $ot_find = $pages->find("template=online_tools, online_tools=$page->online_tools"); But this is as far as I got. Can someone provide me with a hint to get me a little further?
  19. How can I programatically Save() to a Page Type field that contain multiple pages (PageArray)? This attempt fails with no error message, nothing is saved: $p = $pages->get(1234); $p->of(false); $p->foo = 4321; # Page Type field, I am trying to update the ID. // $p->foo = "bar"; // $p->foo->id = 4321; # Results in "Fatal error: Exception: Item 'id' set to PageArray is not an allowed type". $p->save(); Observation: It's hard to search documentation and forum entries for this topic because the keywords Page, Type and Save are frequently used in different contexts. I guess the most logical place to find information would be on 1) the "API Variable > $page" page - and/or, the "API Variable > FieldTypes" page. My request is that the documentation at some point will cover how to programatically CRUD each core field type (Checkbox, Datetime, Email, FieldsetOpen, FieldsetTabOpen, File, Float, Image, Integer, Page, Password, (Repeater), Text, Textarea, URL). Merry Christmas and thanks. Related: Create/Update a page programmatically
  20. To get a page by index number from a PageArray is easy: /* returns a page object */ $pagebyindex = $myparentpage->children->eq(integer $num); Now I needed a function which returns the Index of the page from the siblings. It took me a while to figure this out, and I like to share this here: /* returns an integer */ $indexbypage = $myparentpage->children->getItemKey($page); // or $indexbypage = $page->siblings->getItemKey($page); Found this information in http://cheatsheet.processwire.com/ under section PageArray/WireArray and here: http://processwire.com/apigen/ To get complete information about API this page is your (and my) friend. Have a nice day
  21. Let's say I've got a template with a field of a Page type. This field is set to handle multiple options (PageArray). Now, I want to select all pages using this template, that have specific page set in the PageArray field. Basically, something like this: $pages->find('template=x pagearrayfield.contains=page1') Is this possible? Any hints? Thanks in advance.
  22. I'm not able to get my array list. I have a menu template and I'm grabbing it, but it won't let me go inside it I get this error Warning: Invalid argument supplied for foreach() in /x/site/templates/includes/header.inc on line 61 $items = $pages->find('template=menu, title=Toolbar Menu, include=all'); //THIS SHOULD WORK foreach ($items->menu_item as $item) { $output .= '<li><a href="' . $item->link . '"'; if ($item->open_in_new_window) $output .= ' target="_blank"'; $output .= '>' . $item->title . '</a></li>'; } I'm attaching a screenshot of a selector test
  23. I'm trying to sort a PageArray by $page->name and because there are digits in the name I need to use a natural sort (like php's natsort()). I've gone through the process outlined in https://processwire.com/talk/topic/3392-emulate-natsort/ but I must be missing something because I can't get it to work at all. I then tried a different way and created an array of the page names, used natsort and implode to give me a correctly sorted string to use in a selector. I then do $output = $pages->find("name=$selector_text"); and the correct pages are returned but they're not in the same order as in my selector string. I've only found a couple mentions of natural sorting on the forums so I must be missing something simple but I just can't put my finger on it.
  24. Hi Guys, So I have a template lots of articles . Approximately 23559 pages . I have a field article_id in say example template which is of type of PageArray to the articles template. Now when you try to load that particular template ( example ) PW is becoming slow.... And yes another server we have around 293363 pages and this can grow. So what is the best way to get much speed, or say the PageArray not to load all the stuffs for this is mainly used from an admin point of view. Any suggestions is welcome. Thanks
  25. Hi all, i have some problems when trying to add more pages with asmSelect. I have a field called "categorie" that contains an array of pages ( imagine the behavior of categories ). If i try to add one page from that field all works fine, if i try to add more than one page i get this error: I found that "1007" is the id of the default language. Maybe could be useful for reproduce this error. The field config is like this: There is something that i am missing ?
×
×
  • Create New...