MilenKo

Members
  • Content count

    193
  • Joined

  • Last visited

Community Reputation

39 Excellent

About MilenKo

  • Rank
    Sr. Member
  • Birthday September 17

Contact Methods

  • ICQ
    99982787
  • Skype
    mikemastercorp

Profile Information

  • Gender
    Male
  • Location
    Montreal, Canada
  • Interests
    Web development, coding, Network infrastructures, Linux, BSD, Windows, Cisco, Photography, Cooking

Recent Profile Visitors

460 profile views
  1. If you want even shorter version of your code, you can remove completely the repeating lines and just leave the differences as @szabesz suggested earlier: <?php foreach($page->Slides as $Slides) { $image = $Slides->images->first(); if ($Slides->Link) { $link = $slides->Link; } else { $link = ""; }; echo "<li data-transition='$page->Slide_Effect' data-slotamount='7' data-link='$link' data-target='_blank' >"; echo "<img src='$image->url' alt='$image->description'>"; echo "<div class='tp-caption' data-x='100' data-y='115' data-speed='700' data-start='1000' data-easing='easeOutBack'><h2>$Slides->title</h2></div>"; echo "</li>"; } ?> Hope that helps
  2. <?php foreach($page->Slides as $Slides) $image = $Slides->images->first(); if ($Slides->Link) { ?> <li data-transition="<?php echo $page->Slide_Effect; ?>" data-slotamount="7" data-link="<?=$Slides->Link ?>" data-target="_blank" > <img src="<?php echo $image->url; ?>" alt="<?php echo $image->description; ?>"> <div class="tp-caption" data-x="100" data-y="115" data-speed="700" data-start="1000" data-easing="easeOutBack"><h2><?=$Slides->title ?></h2></div> </li> <?php } else { ?> <li data-transition="<?php echo $page->Slide_Effect; ?>" data-slotamount="7" data-target="_blank" > <img src="<?php echo $image->url; ?>" alt="<?php echo $image->description; ?>"> <div class="tp-caption" data-x="100" data-y="115" data-speed="700" data-start="1000" data-easing="easeOutBack"><h2><?=$Slides->title ?></h2></div> </li> <? }; }?> Something like this might make it shorter. Please excuse me if I forgot to close a { or else as the browser is not my best editor. Basically I removed $image defininition in your second case as it is already defined before the if and is not changing.
  3. Ok, giving it a bit of a time and following up made me rethink the approach. As far as it was done to be working, but the code was still not good (only the last-in-row) was applied on the small posts, I decided to go for odd:even and that did the job as needed: <div class="masonry-grid" data-layout-mode="fitRows"> <?php $i=1; // Defining the rows counter $recipes = $pages->find("template=recipes-inner, sort=-published, limit=12"); foreach($recipes as $index => $latest) { // $class = ($i & 1) ? 'first-in-row' : 'last-in-row'; // Checking up if the result is even or odd and assigning proper class if ($index % 6 == 0 || $index % 6 == 1) { ?> <!-- Checking up for the first and second post in an array of 6 --> <!-- Large Post --> ... Your Code ... <!-- /Large Post --> <? } else { ?> <!-- Small Post --> ... Your Code ... <!-- /Small Post --> <? } $i++; } ?> </div> Now I can move on knowing that the class is applied properly on every post and the first two in the row of 6 are large as the theme required.
  4. Ok, having some ideas thanks to @LostKobrakai, @Macrura and @fbg13 I started playing with the results to see what is going to happen. I must admint that the PHP Modulus operator really made my day and would digg more into it as it literally would solve any of my future needs for every N-th or result-on-every - kind of queries. With some code tinkering I was able to get the posts showing, however instead of starting with two large, it started with a small followed by two large. That made me think why so in the title field I echoed $index and that shown the reason. The modulus result started from 0 but not from 1.That was easy to fix by quering $is_large = $index + 1 % 6 ... but I decided to make it simpler so instead of checking if the result is 1 & 2, I got it checcking for 0 & 1. That showed the results properly (2 large, 4 small, 2 large, 4 small). As usual it won't be that pleasant if there are no challenges... I noticed that the results are not properly alligned to the code grid. Looking at the theme code I found that there are two different styles for the first and second post in the row. So following the same logic, I came up with the following code that made it work like a charm: <div class="masonry-grid" data-layout-mode="fitRows"> <?php $recipes = $pages->find("template=recipes-inner, sort=-published, limit=12"); foreach($recipes as $index => $latest) { if ($index % 6 == 0 ) $class = 'first-in-row'; // Post aligned to left elseif ($index % 6 == 1 ) $class = 'last-in-row'; // Post alligned to right if ($index % 6 == 0 || $index % 6 == 1) { ?> <!-- Define code for first two results --> <!-- Large Post --> <div class="masonry-item any half <?=$class?>"> ... </div> <!-- /Large Post --> <? } else { ?> <!-- Define code for the other 4 posts --> <!-- Small Post --> <div class="masonry-item any half <?=$class?>"> ... </div> <!-- /Small Post --> <? } } ?> </div> So far so good. Event though the code works fine, I am wondering would it be possible to avoid a double query and make it more elegant. Any suggestions are more than welcome and greatly appreciated (as usual)
  5. Learning ProcessWire is like learning to live the PHP life for Dummies ;)

  6. @LostKobrakai Thank you very much for your simple but elegant example. I am just a bit confused about implementing your code with the recipe results array. What would be $post content.. If I got it correctly, $post would be my get/find results query? $recipes = $pages->find('/recipes/'); foreach($recipes->getValues() as $index => $post) { $is_large = $index % 6 == 1 || $index % 6 == 2 if($is_large) … else … }
  7. Hello again. I have done most of the functionality, fields etc. so now am back to the presentation and to that styling grid. My need is to have an array of 10-12 posts, where the first two are large images (different styling and code), the next 4 are smaller images (code differs from the first ones). After the first 6 the array repeats. For sure I can do an array of all 12 posts and do some if/then check for the counter being 1, 2, 7, 8 but I am looking of an elegant way to achieve that as I might need to have 18, 24 etc. so having a check of the counter would become silly the more results I will have to pull. I thought i could grab the first two elements using something like: $large = array_slice($input, 0, 2); $small = array_slice($input, 2, 2); but am not sure how to tie up the things with the loop so that it repeats until the N-number of results in the array...
  8. @Sanyaissues Thank you for your reply. Sorry for my delayed response as I got distracted and being away from my computer and web development for some short time. I was thinking of the best approach for my case and decided to do it through a simple text block where i am filtering the results (every \n is considered one ingredient) and the parts are read through the line in a loop (every word separated with space or other symbol). So at the moment I have something like this: 250 ml whipped 40% cream (Animal source) Where the text is converted to: a[0] = quantity a[1] = measurement a[2] = ingredient (any words content before the opening bracket symbol " ( " a[3] = additional instructions (pink tooltip on the image) Having that approach allowed me to style the recime measures, measurement units, ingredients and instructions separately giving more freedom. And on the other side, to me it is much easier to just copy/paste a recipe from notepad and I did my best to follow the standard for adding recipes with additiona info (using brackets). Oh, and what would be a recipe without the ingredients/instructions dividers - so for this thing I added a lookup for #...# which is styled separately and is considered as Ingredients/Instructions divider (ex. For the salad, For the sauce etc.) One last thing - I removed any \n as sometimes people tend to leave a few line breaks and that was considered as a new ingredient/instruction step. Now everything works fine so here is a short demo content of a recipe and the image how that gets converted (image attached) #For the dough# 250 ml whipped 40% cream (Animal source) 1 pod vanilla (Without the sticks) 1 sachet gelatine 2-3 Tbsp of rice syrup #For the cream# 150 gr blackberries and blueberries 2-3 Tbsp of rice syrup I might experiment with other ways of having the same thing and simplifying it but for the moment I already passed that point so both - ingredients, instructions and Tips are done in an identical/similar way. P.S. It is not close to your ingredients listing which I really liked but I would rather start popularising the site and then decide which way to go as you were following the client needs/instructions but i am more looking at my needs and simplicity to add recipes during busy timee from my phone, tablet etc. So far so good, the rest is to be seen yet as I am aiming now at some more filters to allow recipes to be selected by wanted/not wanted ingredients etc. That should not be hard to achieve but takes time and trial/error for a newbie like me
  9. Ok guys, I guess being tired sometimes takes your concentration away. This morning I decided to use the same approach I used for the human readable time and the ISO 8601 duration is now fully working. As far as I can't think of a use for a period longer than X-days, I did not added the years format in human readable nor ISO but if someone needs it, just follow the logic and you will be good. Here is the code that I used: <?php $d = floor ($page->recipe_cooking_time / 1440); $h = floor (($page->recipe_cooking_time - $d * 1440) / 60); $m = $page->recipe_cooking_time - ($d * 1440) - ($h * 60); if ($d > 0) { $cooking_time = $d . 'd '; $itemprop = $d . 'D'; } if ($h > 0) { $cooking_time .= $h . 'h '; $itemprop .= 'T' . $h . 'H'; } if ($m > 0) { $cooking_time .= $m . 'm'; $itemprop .= $m . 'M'; } $itemprop = 'P' . $itemprop; ?> If someone has a more elegant approach, please share it. My goal was to remove any 0 days, hours or minutes if the time field calls for less.
  10. @LostKobrakai Even though you said that DateInterval is stupid, I found it as one of the sollutions but gave up on it as it blows an error on new DateInterval when the time is in minutes but not already in ISO format. I know I could either change the field to add the time as a text field and add there the time in ISO or else that would be easy to convert, however I am more eager to find out a more custom approach as in our life we could never know what to expect from tomorrow
  11. @LostKobrakai I checked the link you kindly provided, but this is to convert time in different formats but I do not see it doing it for the ISO standard. @Cengiz Deniz Thanks for the suggestion. It loos shorted for sure, now the question would be to make it work promptly for the format of days, hours, minutes as some recipes might require longer than 23h 59 minutes to prepare and I need to make sure that if day or hour are empty, they do not show as 0d 0h 25m (for example). But I will test your solution adding the day and see if that works or not. Still I am missing the ISO formatting. I believe I can do the same approach as with the human time modifying the code but will test today and if working will share it back.
  12. Hello. Working on my cooking recipes profile I need some time conversion to preptime duration as per ISO 8601. For the moment I have a few lines of code that take the value of $page->recipe_cook_time (in minutes) and convert it to human readable time for the frontend (ex. 1d 2h 35m): $d = floor ($page->recipe_cooking_time / 1440); $h = floor (($page->recipe_cooking_time - $d * 1440) / 60); $m = $page->recipe_cooking_time - ($d * 1440) - ($h * 60); if ($d > 0) { $cooking_time = $d . ' d '; } if ($h > 0) { $cooking_time .= $h . 'h '; } if ($m > 0) { $cooking_time .= $m . 'min'; } Now I am trying to convert the minutes of $page->recipe_cook_time into ISO 8601 duration (ex. P1DT1H35M) but am stuck and get different results instead of the right timing. Any suggestions about the conversion or even if you know of a function that can smarter convert minutes to human readable D:H:M ?
  13. Thanks for the suggestion cb2004. That could also do the trick
  14. Hello all. Yesterday working on my Cooking Recipes profile I stumbled across an interesting issue - how to show pages published/created on a specific time interval without the use of any plugins but just the default API of PW. Thanks to @abdus the sollution was implemented and was working perfectly fine (here) Everything was good until I started working on my main page and discovered that our web designer made the recipes appear in threee columns and to differentiate the columns he used 3 different classes (first, second, last). So it was supposed to look like this: <li><class="cs-recipes first"></li> | <li><class="cs-recipes second"></li> | <li><class="cs-recipes last"></li> At first I thought it would be easy to just create another loop and insert it within the first one, but that got me unprepared as instead of 5 posts (as the limit was), I was showing 15. So moving here and there, trying and trying for quite some time to find a solution, I got stuck and asked for some help. Mr @abdus saved the day again offering something simple and most important - fully working. As far as it was a PM, I decided that it would be a shame if I don't share it with anybody else who might sooner or later search for similar functionality, so here is the complete sollution that works perfectly fine and applies the first, second, last as it should without creating unnecessary loops etc.: Hope it helps and don't thank me, I am just the messenger
  15. Ok, now we got a better result Thank you @abdus