Jump to content

Robin S

Members
  • Posts

    4,772
  • Joined

  • Last visited

  • Days Won

    302

Everything posted by Robin S

  1. This rules - so useful! Thank you @adrian, thank you @owzim!
  2. Here is an example of grouping news items under date headings according to a "post_date" datetime field. The headings are the dates (formatted as per the "Date Output Format" specified in the datetime field settings), unless the date equates to "Today" or "Yesterday", in which case those strings are used. You should be able to adapt this to your needs. $news_items = $pages->find("template=news_item, sort=-post_date"); $previous_item_date = ''; foreach($news_items as $news_item) { if($news_item->post_date !== $previous_item_date) { $timestamp = $news_item->getUnformatted('post_date'); if($timestamp >= strtotime('today')) { $date = 'Today'; } elseif($timestamp >= strtotime('yesterday')) { $date = 'Yesterday'; } else { $date = $news_item->post_date; } echo "<h3>$date</h3>"; // output the date heading } echo "<p>$news_item->title</p>"; // output whatever fields of the item $previous_item_date = $news_item->post_date; }
  3. In earlier versions of PW, all repeater items in a page would be loaded when opening Page Edit - this could cause problems if there were a lot of repeater items. But in recent versions repeater items may be ajax-loaded, meaning repeaters can now scale up much better than previously. So there's no reason to avoid repeaters. Also see Repeater Matrix, which is more similar to PageTable in that it allows for multiple matrix types (sort of equivalent to templates). You could use RuntimeMarkup in conjunction with a Page Reference field. You would configure a RuntimeMarkup field to get and format the fields from band pages currently selected in the Page Reference field. Note that after changing the Page Reference field you would need to save the page in order to see the RuntimeMarkup field update.
  4. I have been playing around with the code from @Raymond Geerts, getting the pagination working. Thought I would post this for posterity: $limit = 10; $limit_first = 8; $offset = $limit - $limit_first; if ($input->pageNum == 1){ $results = $pages->find("limit=$limit_first"); } else { $start = (($input->pageNum - 1) * $limit) - $offset; $results = $pages->find("start=$start, limit=$limit"); } // output result items echo $results->each("<p>{name}</p>"); // override pagination $results->setLimit($limit)->setTotal($results->getTotal() + $offset)->setStart((($input->pageNum - 1) * $limit)); // output pager echo $results->renderPager();
  5. You or your client must have some deep pockets for font licensing. From the DTL website:
  6. Welcome to the forums! I think you're on the right track here. Not sure that you need an end date field in the band description repeater - just the start date (a datetime field that defaults to today's date). In your event template file, for each selected band page you would get the most recent band description that is dated earlier than the event date. Inputfields such as AsmSelect have an option to edit pages in a modal window.
  7. Yep, you want a Page Reference field on the child pages. For "Label field" select the text field used in your repeater. Use the "Custom PHP option" for "Selectable pages" by creating the following hook in /site/ready.php: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'my_page_reference_field') { $page = $event->arguments('page'); $event->return = $page->parent->podcast_show; } });
  8. Using wire('pages') in a template file shouldn't cause an error (not sure why that's happening), but in template context you would normally access this API variable as $pages. In fact, in your screenshot you are doing that a few lines below on line 36.
  9. Check out Runtime Markup: http://modules.processwire.com/modules/fieldtype-runtime-markup/
  10. Hi @xavier, welcome to the ProcessWire forums. The code you have posted looks like AngularJS - I'm not sure this is the right place to get support for that. If you are just getting started I suggest you use straight PHP and HTML for your first ProcessWire project and leave AngularJS until you are more familiar with ProcessWire. That way it will be easier for people to help you here in the PW forums.
  11. Why not? Seems like a paragraph tag is the appropriate markup for a paragraph of text.
  12. Purchasing a dev licence for Form Builder is a no-brainer: if you place a dollar value on your time you will quickly realise that after only a small number of forms it has saved you $$$.
  13. There is a multi-language support subforum: you might do better to ask your questions there. I've never built a multi-language website myself as there is no demand for it in my part of the world (sadly Maori/English dual-language websites are rare in NZ).
  14. Although you can insert a static menu into your template, usually a CMS-powered website would use a menu that is generated dynamically according to the pages in the website. The text in the menu would be sourced from the titles of the pages. To create translations of page titles you can install the language support modules. I suggest you read the language support documentation, and the section about multi-language fields in particular.
  15. This isn't actually an installable profile though - you can explore the template files but without the database from the demo site it's not as useful as it could be. @ryan, could you please make an exported profile of the demo available?
  16. Based on the fact that you do not have URLs in the link hrefs I guess this menu is for navigating to blocks of content within a single page. Rather than hardcode this menu into the template and translate it using __() you could consider using a Repeater / Repeater Matrix for your content blocks and add a title field to your repeater items. Then you can create translations for the titles in Page Edit and generate your menu dynamically. Seems like it would be easier to maintain that way.
  17. If you want pages where a field is not empty you don't need to deal with the fieldsets/templates at all. Just: $count = $pages->count("title!='', has_parent!=2");
  18. Using a primary category in a parent-child relationship has some benefits: Visitors can see the relationship demonstrated in the URL and breadcrumb navigation The site structure is intuitive as visitors "drill down" through the page hierarchy to more specific pages There is some SEO benefit Finding a page in the admin page tree may be easier for site editors But this type of page structure is only possible (or only sensible) when a child page will belong exclusively to a single category of that type. So in the case of the skyscrapers demo it works for the city relationship as a building can only ever be in one city. But it wouldn't work for the architect relationship as it is conceivable that a building could be designed by more than one architect. And you wouldn't want to have duplicated building content under two ore more different architect parents. In the case of a turtle, you could for example use the taxonomical hierarchy in parent-child relationships: Trachemys scripta can only ever belong to a single genus, and so on up the hierarchy. But you wouldn't want to use "Native to" in a parent-child relationship as this would be both Mexico and the United States. @webhoes, matching to a page object / page ID like this is very reliable, but in most cases your Page field (habitat) will be limited to a single template and/or parent and the the titles of allowed pages will be unique. So you can cut out a step and do: $swampAnimals = $pages->find("template=animal, habitat=Swamp");
  19. Try: $template_has_title = $fields->get('title')->getFieldgroups()->implode('|', 'name'); $page_has_title = $pages->find("template=$template_has_title, has_parent!=2"); If you just want the count of the pages rather than the pages themselves you can do: $count = $pages->count("template=$template_has_title, has_parent!=2");
  20. A way you could do this without any code: 1. Create one image field for the first image and one image field for the second/subsequent image(s). 2. Set "Min width for uploaded images" to 200 for the first image field. Incidentally, your original post says that the first image should be under 200 pixels wide, but that doesn't make sense so I assume you mean over 200 pixels wide. 3. Make both image fields "required".
  21. When deciding whether or not to use a parent-child structure to create a relationship, the questions I ask are: 1. Is this relationship a primary (very important) relationship? 2. Do I want the relationship to be revealed in the page URL? (Note that other types of relationship may still be represented in a URL via the URL Segments feature) 3. Is the relationship exclusive? (i.e. may the child only belong to a single category/parent - you want to avoid a situation where the same page would appear under more than one parent). If the answer to any of these is "no" then I use a Page field for the relationship rather than a parent-child structure.
  22. If you just want a notification that a page is currently being edited by another user (like the default behaviour of Page Edit Soft Lock) then the optional core System Notifications module also has that feature. But if you want a "hard lock" option then I think Page Edit Soft Lock is the only option currently.
  23. Instead of... foreach($post->children("sort=-publish_date") as $child) { ...try... foreach($post->children()->sort("-publish_date") as $child) { I assume "publish_date" is a custom field you have added to your template - otherwise perhaps you are looking for "created". More likely "published". What's the deal with all the opening/closing PHP tags?
  24. There was a typo in the hook code I posted: should have been "parents" and not "parent". This should work... $nav = $modules->get('MarkupSimpleNavigation'); $nav->addHookAfter('getItemString', function(HookEvent $event) { $item = $event->arguments('page'); // if the item has more than one parent then it is a subpage if($item->parents->count() > 1) { $event->return = "<a href='{$item->parent->url}#{$item->name}'>$item->title</a>"; } }); // define your options array if needed and render your menu If not please post your MarkupSimpleNavigation code.
  25. Sounds like a good solution, but renderPager() will show a different number of pages on the first page than the others (because it is dividing 100 by 8 instead of 10). So you may need to use a custom pager to get around this.
×
×
  • Create New...