psy

Members
  • Content Count

    276
  • Joined

  • Last visited

  • Days Won

    2

psy last won the day on August 9 2017

psy had the most liked content!

Community Reputation

431 Excellent

1 Follower

About psy

  • Rank
    Sr. Member

Contact Methods

  • Website URL
    http://www.clipmagic.com.au

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

2,638 profile views
  1. @Michkael Doh me! - the class to clear a row in your case needs to be on each 4th item... Recommended change: <?php $i = 1; foreach($page->Services as $Service): $image = $Service->image; $colFirst = ""; if ($i%4 == 0) $colFirst = 'col_first'; $i++; ?> With CSS class: .col_first { clear: both; } Remember to either type the above completely into your IDE or copy/paste into a text-only editor first
  2. @Michkael Sometimes when copy/pasting directly from forum code unexpected and hidden chars end up in the output. I suspect that's what happened here. The (pure) code works but when I copy/pasted to my IDE I found a hidden char after.... "colLast" = "row" in your code. No one's fault and I'm guessing Line 144 was $i++ that failed. Also found that your code <?=colLast"?> had a weird space in it in my IDE. Best practice when copy/pasting from forum code is to paste into a text only editor before copy/pasting into your template to remove any weird, hidden chars. After that and with Bootstrap being your framework, <?=colLast?> in that place will not work for you. Bootstrap needs the row class on its own eg: <div class="row"> <div class="col-md_6"> ... </div> </div> To make it work for you, you could try adding a CSS class: .col_last { clear: both; } to ensure the next item starts on a new line below the previous three
  3. One of the things I love most about PW - and also find frustrating at times - is that there are so many ways to achieve the desired end result. Choosing which way to go at the start of a project can be tough. Whichever method you choose for front-end output can be done in PW
  4. And as a 3rd option, use the PHP modulo feature: http://php.net/manual/en/language.operators.arithmetic.php 1. Set a variable, eg $i to 1 2. Iterate through your (Wire)array and add 1 to $i each time 3. At each iteration, check if $i%3 == 0 and if so, add your row html Example below selects 6 random service items and splits into 2 columns x 3 rows. For each item that returns $i%2 == 0 (2nd row item) I add the class "col_last". Add classes, html as required for your frontend theme - guessing it's Bootstrap <?php $services = $pages->get('name=services')->pgtb_services->findRandom(6); $i = 1; foreach ($services as $item) : $colLast = ""; if (($i%2) == 0) $colLast = 'col_last'; $i++; ?> <div class="col_half service <?=$colLast?> nobottommargin"> <article class=" boxFeature"> ... </article> </div> <?php endforeach; ?>
  5. psy

    Love my iMac and happy to know you love yours too @ryan. Biggest hurdle for me going from Windows to Mac was - really? it's that easy????
  6. Your alt method sounds plausible. Will try it
  7. Thanks @kongondo The page is created automatically by PW, not via the API when the admin clicks on the parent page -> new. I think I need to find the right conditional statement to say return if it's a new page with no required custom fields completed. Maybe instead of checking if the page has an id: if (wire('pages')->added($page)) return;
  8. psy

    This should work too. (I used the method to output the month as a heading for a list of events sorted by start_date). What it does: Gets the first letter of the first child and output it, eg "A" Gets the next child and compares the first letter of its title with the previous child's title first letter If the same, it continues on If different, it outputs the new first letter <h2>Services</h2> <?php if ($page->children->count) : $children = $page->children('sort=title'); foreach ($children as $child) : $letter = substr($child->title, 0, 1); // get the first letter of the title if ($child->id == $children->first->id) : // first child ?> <h2><?=$letter?></h2> <?php else : $prevLetter = substr($child->prev->title, 0, 1);; if ( $prevLetter !== $letter) : // different first letter in title to previous sibling page ?> <h2><?=$letter?></h2> <?php endif; endif; ?> <p><?=$child->title?></p> <?php endforeach; endif; ?>
  9. I have a template that is the only child of a parent template so the admin is not asked to enter a title/name. The page is automatically created and admin presented with the custom fields screen. All good so far. The page name is auto-generated with the date/time. Again all good. Problem occurs once the admin changes fields on the page. The new title and page name is a combination of: 1. Calculation of start date and end date of the event, eg 1/11/2018 to 2/11/2018 results in "2 Day " 2. Title of a page reference field, eg "Long Reining Clinic", and 3. The start date That works providing the clinic title doesn't have an ampersand in it... that results in an Error 403 Permission Denied error when editing the event. Got over that one only just and no understanding why it happens Immediate and bigger problem is that 2 pages are created: 1. First on creation of the page - unpublished with default title and no custom data 2. Second on admin update of the custom fields - often there is a conflict of page ids Below is my hook in ready.php to change the page title & name once the relevant custom fields have been entered. It's taken pretty much directly from the PW docs. The CustomFunctionDDH::clinicDays returns a string as per above, eg "2 Days " /***** Update page title for event/clinic pages */ wire()->addHookBefore('Pages::saveReady', function (HookEvent $event) { $pages = $event->object; $page = $event->arguments(0); if ($page->template != 'event') return; if (empty($page->id)) return; // doesnt work for new pages if ($page->isChanged()) { $title = CustomFunctionsDDH::clinicDays($page) . " "; $title .= $pages->get("id=" . $page->pg_clinic_type_title)->title; $page->of(false); $page->title = $title; $startDate = wire('datetime')->date('d m Y', $page->start_date); $newName = str_ireplace('---', '-', wire('sanitizer')->pageName("$title $startDate")); if ($page->name != $newName) $page->setName($newName); $page->seo_title = $title; } }); What am I doing wrong? Help appreciated Solution: Problem due to operator error/digital malfunction, ie me! Doh! BEFORE I set the page parent template Events to only accept child pages with template Event, I had added one child page with template 'basic-page'. No wonder PW got confused. Changed the parent template Events to also accept child pages with template 'basic-page', problem solved. Now though, instead of automatically going to the 'event' custom fields, the admin must enter a page title (could be aaaaa) and save. Client and I can live with that. Thank you @kongondo for your suggestions. Sometimes the obvious is staring me in the face...
  10. I arrived at ProcessWire via a different path. A few years back, two other developers and I were dissatisfied with the CMS we were using. Other two researched, tested, investigated all on the market except WordPress. We all agreed we'd rather give up than go down that road. Fortunately for me, they both agreed PW was the best and I should give it a go. Haven't looked back. Thanks @ryan, the forum team, Goran and @Stikki
  11. psy

    Hi @thepurpleblob and welcome to ProcessWire Hrmmm, yes your question is a bit hazy and I'm not sure I fully understood it. There are lots of ways to deploy development sites to live including modules to help you through the process. It's my experience that the best way is to: back up/download a copy of the db on the development server (I always install the db backup module https://modules.processwire.com/modules/process-database-backups/) create a new database on the live server and import the db backup from the dev server zip the development files and upload to the live server update the /site/config.php file on the live server to reflect the changes in the db configuration and https hosts options That way, the dev & live server data & files (/site/config.php excepted) are identical including admin logins You may want to install https://modules.processwire.com/modules/process-wire-upgrade/ on both your dev & live servers to easily ensure they're both always on the same PW version Hope this helps
  12. psy

    @LostKobrakai OK, thanks for enlightening me. Was just thinking that if some scumbag got into the db, seeing stuff Base64 encoded would be one more step, rather than having the json string in an immediately readable human language. Main point of the post was warning of the flakiness of PHP serialize/unserialize
  13. This week I was lured to the dark side (my client's own words) to work on a CMS that's not PW or WP. I didn't stay long and it reconfirmed by love of PW but that's beside the point. A problem I encountered was not directly related to the CMS but to PHP itself and how it handles Json serialize/unserialize. Everything functioned for a while then crashed monumentally without any discernible reason. A Google search turned up the following article: https://davidwalsh.name/php-serialize-unserialize-issues Seems to me not only does this solve the problem, base64 encoding data stored in the database would add an extra level of security/privacy. Just sharing...
  14. This works for me... clinics (events) are listed under a Month Year heading. $clinics = $pages->find('template=event, start_date>=today, limit=6, sort=start_date'); if (!$clinics->count) return; $datetime = wire('datetime'); foreach ($clinics as $clinic) : $currentDate = $datetime->date('F Y', $clinic->start_date); if ($clinic->id == $clinics->first->id) : // first clinic?> <h3 ><?=$currentDate?></h3> <?php else : $prevDate = $datetime->date('F Y', $clinic->prev->start_date); if ( $prevDate !== $currentDate) : // different month and year ?> <h3 ><?=$currentDate?></h3> <?php endif; endif; ?> <div class="event-summary clearfix"> <?php // event details here ?> </div> <?php endforeach; ?>