Jump to content

cb2004

Members
  • Posts

    578
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by cb2004

  1. I have been doing battle for the last couple of hours on this, I think I have got it but I just want to double check. Also I couldnt find anything on the forums so this could serve as help for other users. I have a set of child pages that hold a date. I want to do a find on those children for those with date>=today and then spit out the parents to then handle further logic. I feel like I am missing something that ProcessWire can do here so please let me know if you know of a better way. $results = $page->find("date_1>=today, sort=date_1, parent.status<" . Page::statusUnpublished); foreach ($results as $p) $parents[] = $p->parentID; $results = new PageArray(); $results->add($parents); ProcessWire should handle the unique parents as the first $results may return 1001,1002,1001 for example. Thanks as always people.
  2. On a homepage I have got some calls to action and I was just wondering whats the most optimised method. Does PW have this in the API? <?php $ctas = [ 1038, 1039, 1040, ]; foreach ($ctas as $cta): $p = $pages->get("$cta"); ?> <div class="home-cta"> <a href="<?= $p->url ?>"> <img src="<?= $p->image_cta->url ?>"> <h2><?= $p->get("text_1|title") ?></h2> </a> </div> <?php endforeach; ?> Cheers.
  3. I rock at regex regex:^[0-9-]+$
  4. I must admit, regex is certainly not my strong point. What would I have to put in to allow for an urlSegment of say 2015-2016? Thanks people.
  5. We had to add this to our latest project and I am happy to share here. I couldn't find anything on the forums for this so apologies if it has been done before. But there are always different ways of doing things: $firstEntry = $pages->find("parent_id=1037, sort=date_1, limit=1"); foreach (range(date("Y"), date("Y", $pages->get("$firstEntry")->date_1)) as $year) { $start = strtotime(date("$year-01-01")); $end = strtotime(date("$year-12-31")); $count = $pages->count("parent_id=1037, date_1>=$start, date_1<=$end"); if ($count > 0) echo '<li><a href="' . $page->parent->url . $year . '/">' . $year . '(' . $count . ')</a></li>'; } So what is going on: first of all, our pages were children, so we set the parent_id, and our date field is called date_1 we need to get the year of the oldest entry, so that happens with $firstEntry and a simple find next we create an array using a range of years, we start with the current year, then we get the year from our $firstEntry (note: if you have an output format for your date set in the field settings you will want to use $pages->get("$firstEntry")->getUnformatted("date_1") within the foreach) next we create a start date and end date for the year we count if there are any entries for that year if there are display them in a list Your next step would be to create the $input->urlSegment code to display your pages.
  6. Good work tpr foreach ($page->children("(date_1=), (date_1>today)") as $news)
  7. I have added an expiry field (date) to a template for articles which would need to expire. Some articles would not have an expiry date set, so I need to in theory display articles with a blank date or >today. I am wracking my brains but it is tired today, so I am looking for something along the lines of: foreach ($page->children("date_1=|>today") as $news) Cheers
  8. I have creating a website that reads an XML file to pull in products (pages). When a product is out of stock in the XML file, this page becomes unpublished. I want to display a different 404 message to what is usually seen if a product is unpublished and was just wondering the best way to go about this? Or would the best thing be to set it to hidden, and then check if the page is hidden on the template level and do the logic there? Cheers.
  9. That did it, options field and ("sort=dropdown, sort=price")
  10. Ok it got a bit more interesting. Text could have Available, Coming Soon or Not Available with prices. I want them to appear like: Available sorted by price Not Available sorted by price Coming Soon sorted by price Easily done with 3 foreach blocks but was just curious.
  11. Hi all, hope everyone is well. So, I want to return the results where the text field matches 'a' and sort those by 'price', then display the results where the text field matches 'b' and sort those by 'price'. Is ProcessWire capable of this or do I just need to do a couple of foreach?
  12. Is cache set on the template used for internal pages?
  13. Ah, I see what you mean now Sebii, your solution looks like it would work perfectly. I will report back when I get round to building the search. Thanks.
  14. Yeah, I always find a text field as a search an odd one, is the user expected to know what to search for. But thats what the client wants. There is also no textarea fields for the products which means its harder to search for keywords. I think my idea could work, so the user would type in "red" as their search and any products with "red" in the field search_tags would show up. This fields data could be: red, blue, small, large, manufacturer
  15. I haven't used the search in ProcessWire yet, but I have a project coming up that will require it. It is kind of an ecommerce setup where the product has options like manufacturer, colour, size etc. These are managed by the client using a page structure of: - Options - Manufacturers - Manufacturer - Manufacturer When a product is added these options are then selected using page selectors. On the site there is a requirement for the search field (text), however I am thinking as the options will not appear in the actual product data (red, blue, small, large), they will just be id's to relate to the pages, the products will not appear in the search results. So my thought process is this, hook into save and populate a text field with csv (Search tags) all of the text from the selected results e.g. red, small, then when somebody searches for red, the products will appear. Does that sound like the best way?
  16. Ben provided the correct hook here: https://github.com/ryancramerdesign/ProcessWire/issues/1832 So we end up with: $pages->addHookBefore("ProcessPageEdit::processInput", function($event) { $page = $event->object->getPage(); // apply job title if a quote is selected, apply customer address if customer selected if ($page->template->id == 48) { if ($page->page_quote && empty($page->title)) { $page->setAndSave("title", $page->page_quote->title); } if ($page->page_customer && empty($page->textarea_1)) { $page->setAndSave("textarea_1", $page->page_customer->textarea_1); } } });
  17. This is what you have to love about ProcessWire. Fantastic release last week, some feedback from users, then an even better release 7 days later. 2 small requests from me. Tooltips/titles for the icons for the different views. Reset to default for the slider. Keep up the great work team.
  18. I am building a system which has a page selector using the template user. When the page is added I wish to autopopulate the page_user field with the logged in user, but they can also change this should they wish. This doesnt seem to work: $pages->addHookAfter("added", function($event) { $page = $event->arguments(0); if ($page->template->id == 57) { $page->setAndSave("page_user", $user); } } I have also tried numerous other things like $page->page_user = $user, and lots of variations but no joy. What does actually work is something like $page->setAndSave("page_user", 41); so its not reading the logged in $user, even if I do something like $user->id. Any help would be appreciated. Cheers.
  19. Fantastic module. Thank you.
  20. I am using hooks to populate some required field values. The populating is done, but I get an error message if it is a required field regardless if it has been populated. Which hook should I use to save the values, then the page displays without an error? Cheers. $pages->addHookAfter("save", function($event) { $page = $event->arguments(0); // apply job title if a quote is selected, apply customer address if customer selected if ($page->template->id == 48) { if ($page->page_quote && empty($page->title)) { $page->setAndSave("title", $page->page_quote->title); } if ($page->page_customer && empty($page->textarea_1)) { $page->setAndSave("textarea_1", $page->page_customer->textarea_1); } } });
  21. I could be wrong but I think LostKobrakai edited his post from $page->text_1 = "test"; to $page->setAndSave('text_1', "test"); as I revisited his solution and it worked fine.
  22. I have a working solution. I am taking a guess that it cannot update a field directly in the page you are saving without a bit of extra information: <?php $pages->addHookBefore('added', function($event) { $page = $event->arguments(0); if ($page->template->id == 46) { $p = wire('pages')->get($page->id); $p->setAndSave("text_1", "test"); } }); The solution by LostKobrakai works as well.
  23. I tacked on $this->message("WORKING"); just to make sure I got this message and I did.
×
×
  • Create New...