Jump to content

MilenKo

Members
  • Posts

    466
  • Joined

  • Last visited

Everything posted by MilenKo

  1. 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)
  2. @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 … }
  3. 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...
  4. @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
  5. 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.
  6. @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
  7. @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.
  8. 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 ?
  9. Thanks for the suggestion cb2004. That could also do the trick
  10. 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
  11. Ok, now we got a better result Thank you @abdus
  12. @abdus I tested your code using DateTime class, but am getting a server error 500: $today = new DateTime(); $aFewDaysAgo = $today->modify('-2 days'); if($pages->get('/recipes/')->children) { $latest = $pages->find("template=recipes-inner, published>=$aFewDaysAgo, sort=-published, limit=9"); and the error in exceptions.txt is: Object of class DateTime could not be converted to string.
  13. Ok, so it looks like DateTime class would do the trick if I ever want to present some pages in a specific timeframe. Thanks again @abdus & @Robin S
  14. OK, that seemed to work and shows some results. Now if I want to show dates 2 or 3 days ago, would it be correct to have $start = strtotime( date(('Y-m-d')-2) . " 00:00:00"); or there is a better/correct way of doing it? Also let's say I need to show the pages for last 7 days?
  15. @Robin S Thanks for the advise. I thought so, but I am getting an error on my code: <ul class="cs-recipes"> <?php $start = strtotime( date('Y-m-d') . " 00:00:00"); $end = strtotime( date('Y-m-d') . " 23:59:59"); if($pages->get('/recipes/')->children) { $items = $pages->find("template=recipes-inner, $page->published>$start, $page->published<$end, sort=date, limit=9"); foreach($items as $rotd) { ?> <li class="cs-recipe"> <div class="cs-recipe-image"> <div class="cs-recipe-details-button"> <a href="recipe_single_layout_1.html">Details</a> </div> <img src="<?=$rotd->recipe_image->url?>" alt="<?=$rotd->recipe_image->description?>"> </div> <div class="cs-recipe-meta"> <span><i class="fa fa-hourglass-half"></i> <?=$rotd->recipe_cooktime?></span> <span><i class="fa fa-cutlery"></i> <?=$rotd->recipe_servings?></span> </div> <h3> <a href="<?=$rotd->httpUrl?>"><?=$rotd->title?></a> </h3> </li> <? } ?> </ul> Any ideas where did I messed it up this time?
  16. Hello all. I am trying to find a way to have a query with all pages that were published on a specific date (today for example). I read a few posts where people had a specific date field and were limitting the results by that, however is there a way to filter results without a specific date field? As far as I am able to publish the timestamp using $page->created logically I should be able to filter by the result of it? What is the best way to accomplish a filter for a day, week, month etc.?
  17. Hey Abdus, I just noticed that we are almost neighbors with you as I am originaly from Bulgaria and I flew quite a few times to my home via Istanbul :)

    As far as I noticed your blog in the signature and that you are working with Web design professionally I might have a few jobs for you if interested.

    As I am about to finish soon my IT Website, offering different IT services locally in Canada I would not miss to list the web development, so my idea is to establish some connections with good web devs and work through projects together (of course for the price agreed etc. that would be evaluated and confirmed in advance).

    Would you be interested for some future projects if a request comes to me?

    1. abdus

      abdus

      Yep, sent you a PM

  18. @abdus I found the issue and eliminated it. It appeared that the problem was caused by another check for $nutrition->name before printing the $content if(!empty($item->name)) { echo $content; } ?> As soon as I removed the if-check as we are already checking up for empty $item->name before that it worked like a charm! The full code shared above has been edited to provide the fully working sollution.
  19. Yes, the text is 1:1 and if I only add another line it shows up every value promptly. Changing the metrics and quantity appears correct in the list too...
  20. For the test I just removed the last 4 of the afore mentioned values list: Calories: 1000 kCal Fats: 10 gr Saturated: 15 gr Salt: 1 gr Theoretically it should still find the 4 and list them but...
  21. @abdus I just noticed something strange - if I have only 4 values, they don't show at all... I checked up the code to see if it could be an overlapping of divs etc, however it is not showing in the page source either: <div class="cs-nutrition-list"> <h4>Nutritions</h4> <ul> </ul> </div> If I add more than 4 nutrition rows - it shows them ok.. The happiness did not last long
  22. OK. Now you nailed it!!! Here is the final code used to make the nutrition work: I think this would be useful to have for several other locations where a need would be to separate text lines from an textarea field and populate the values if not empty. One less task to deal with thanks to you @abdus!
  23. @abdus for some reason even checking for $item->value being empty did not stop the loop to show the empty <li></li>: We are so close, but still...
  24. @abdus You were right, I misplaced the $content result before the end of the loop. I also noticed that I inserted the <ul> inside the list which was breaking the order, so I moved it out of the equation and it worked fine. The only thing to look at is that if I miss to add a value of the nutritions it shows an empy <li></li> and that messes up the style. I tried to check if the result is null/empty and if not to echo $content: if (!empty($item)){ echo $content; } But It still shows the empty values ...
  25. @abdus I tried to implement your order code but it got messed up and repeats every field 3 times or more. Here is the code I used:
×
×
  • Create New...