Jump to content

MilenKo

Members
  • Posts

    466
  • Joined

  • Last visited

Everything posted by MilenKo

  1. Hello all. I am trying to imlement the comments on my main page as well, however my need is just to print the page name, the author and the date of the last N-comments. The examples above are meant to render the comments itself, where I am trying to pull up the pages ccontaining those comments and get them ordered. So I thought I could try something like this: $com = $pages->find('template=articles_inner, comments>0, sort=comments->created'); or $com = $pages->find('template=articles_inner, comments!="", sort=-comments->created'); but it just shows no results. My template name is "articles-inner" which implies for all child pages added as articles so the template name is correct. The field name that holds the comments is: "comments" so that is also correct, but what got me was that I am not aware how to check if the field contains some value (not empty) and also how to sort the resulted pages by comments post date. Any ideas or suggestions?
  2. If I understood correctly what is the need, here is another simple idea I used in the past to have a text field where you can add hundreds of url's one per line. After that, wherever you need to pull every url, you just grab the line and you are done: <?php foreach(explode("\n", $page->your_urls_text_field) as $url) { // Explode every new line as a new url echo "<p>$url<br />"; //You can add <a href.. etc. } ?> The only requirement is to have every new url on a new line to make it work. Hope that helps...
  3. @Robin S I knew it would be that easy, but was missing the point. Thank you very much. Here are the changes applied that worked just fine for my needs: // Search the title, body and sidebar fields for our query text. // Limit the results to 10 pages. // Exclude results that use the 'keywords' template. // Search within the following fields: title, body, keywords, file name, file description $matches = $pages->find("template!=keywords,title|body|keywords|file_upload|file_upload.description%=$q, limit=10"); The elegance of PW is amazing me everyday even after considering the fact that I am having still a lot of PHP to learn to get to more advanced levels. Thanks again.
  4. Hello. Earlier I was able to implement a simple search on a knowledge sharing project for my company but now I was asked to add some functionality where to any page some files can be attached. It went pretty straight forward to use the FieldTypeFile and show up on the frontend all attached files by names. After completting the task I thougth that I could expand my search results allowing the query to search for a string within the attached file names and/or description. So on my working query: $matches = $pages->find("template!=keywords,title|body|keywords~=$q, limit=10"); I tried adding the files_upload field which I created and assigned some file types. The final query got: $matches = $pages->find("template!=keywords,title|body|keywords|file_upload~=$q, limit=10"); but I got a long error text: Error: Exception: SQLSTATE[HY000]: General error: 1191 Can't find FULLTEXT index matching the column list (in C:\OpenServer\domains\nowknow.pw\wire\core\PageFinder.php line 384) #0 [internal function]: ProcessWire\PageFinder->___find(Object(ProcessWire\Selectors), Array) #1 C:\OpenServer\domains\nowknow.pw\wire\core\Wire.php(374): call_user_func_array(Array, Array) #2 C:\OpenServer\domains\nowknow.pw\wire\core\WireHooks.php(549): ProcessWire\Wire->_callMethod('___find', Array) #3 C:\OpenServer\domains\nowknow.pw\wire\core\Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageFinder), 'find', Array) #4 C:\OpenServer\domains\nowknow.pw\wire\core\PagesLoader.php(216): ProcessWire\Wire->__call('find', Array) #5 C:\OpenServer\domains\nowknow.pw\wire\core\PagesLoader.php(216): ProcessWire\PageFinder->find(Object(ProcessWire\Selectors), Array) #6 C:\OpenServer\domains\nowknow.pw\wire\core\Pages.php(225): ProcessWire\PagesLoader->find('template!=keywo...', Array) #7 [internal function]: ProcessWire\Pages->_ This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged. Obviously I am not getting the correct way of searching for a file name or file description in the query. Any ideas how to accomplish that?
  5. Hello guys. Searching today for page hit counters I stumbled acros your sollution which was working back then. Would you know if the approach would still work with 3.0.6X or if there is a wiser approach to take for a 'clean' page hit counter that would not include bot counters, page reloads nor super user visits?
  6. Well based on the XAMPP error you mentioned, if you did not already tried to redownload the source and try to install PW - I would do that before testing any other server. I was using XAMPP in the past, then switched to Ampps but found the OpenServer to be the best feature and parameters wise so switched to it. I would think that you might have had an issue with a setting in XAMPP apache modules or else, but to not be able to install the PW, maybe it is not right to blame the server itself. One other thing I could suggest (just to be safe here ) would be to do a drive scan for errors as I had several cases where customers complained of not being able to open files but after a scan of the HDD their issues were "miraculously" fixed (I know it sounds too much but it is a possibility )
  7. Guys, after a few tries, I got it fully working without the use of urlSegments. What I did was to grab the url and extract the last segment of it after removing the backslashes before and after and assigning the result to my category variable: <? $url = trim($_SERVER['REQUEST_URI'], '/'); $path = explode ('/', $url); $cat = end($path); $results = $pages->find("template=recipes-inner, recipe_category={$cat}"); foreach($results as $recipe) { ?> ..... your code ..... <? } ?> To simplify it a bit I was able to combine the first three lines into a fully working single one: $cat = end(explode('/', trim($_SERVER['REQUEST_URI'], '/'))); but got an error in Tracy Debugger: PHP Strict standards: Only variables should be passed by reference - so had to split it to be code standards compliant. Tested to add a subcategory inside a subcategory and it also worked fine as far as I assigned it to an existing recipe so I can jump to the next task of my plan. Thanks again to all of you guys, who guided me and helped to stay on the right path and keep on going. All the best!
  8. @devlisa I am working with ProcessWire under Window$$ and have never had any issues. To make sure it is working fine, I would suggest you to try OpenServer which is much much more than just a WAMP and has super control over your server. On top of that, it creates a folder ../domains/ so any folder you place there would become an active domain after a server restart by adding a record of it to your hosts file (if you allow it). Here is the URL for the server to download (just type the numbers at the field, leave the distribution dropbox by default and click on the button next to it - the page is in Russian but can be easily translated with Chrome etc. Oh, and it is absolutely free with no add/spy-wares and whatsoever. There are only two minor things to consider - it is being actively developed by a Russian team which might have some settings on Russian but you have the ability to change to English or whatsoever. The other thing is its size - about 1GB for the whole pack which includes a few test browsers, phpmyadmin and so on and so forth. The cherry of the cake is that PW works out of the box with. Same thing happened with WP, Presta, etc. Good luck!
  9. @fbg13 your assumption is correct and yes, there is a parent Category and a child page - Bakery. It is my misunderstanding of what the urlSegments are used for. After your suggested test and reading a bit I found out that there is nothing wrong with the setup and it seems that the urlSegments are not meant to work for an existing url. As far as I just need to read the last segment of the url and filter the results of it, I think that should work the way I need it (not depending on the deepenes of subcategories level). Let me try that and will share how it works.
  10. @fbg13 as I wrote earlier, for the /category/ url I use 'categories' template. For any child page inside the category (eg. /category/bakery) i use 'categories-list' which got confirmed by the $page->template->name. The whole idea for the approach was to have the category template list all the categories that are just children pages of Home > Recipe Categories and have only a few fields - title, category_icon, category_image, category_description So browsing to food.pw/category/ would list ONLY the categories with their images linked to the category url: Bakery would be food.pw/category/bakery. As far as I just needed to resolve the name of the subcategory after the /category/ and use it to filter the recipe results to only those that have 'bakery' assigned as a category. I think I can grab the url using $_SERVER['REQUEST_URI'] and trimming it a bit to get the last part. However I am not sure would this approach would allow the caching to be working properly so will experiment a bit and see what would happen. I already tried to add this code to the url-segments.php (as per your earlier suggestion): <?php $segment = $input->urlSegment; //Just to test segments $url = $_SERVER['REQUEST_URI']; //Get the url segments after the FQDN $path = explode('/', $url); //Removing the backslashes from the url $cat = end($path); //Obtain the last part of the url as the category to filter echo "Segment: " . $segment . "<br />"; echo "URL: " . $url . "<br />"; echo "Catetory: " . $cat . "<br />"; ?> And as a result I got: Segment: i-am-a-segmentURL: /urlsegments/i-am-a-segmentCatetory: i-am-a-segment So even if I decide to have subcategories, I would still be able to resolve the last one and filter results by $pages->find('template=categories-list, recipe_category=$cat) Brosing to: http://food.pw/urlsegments/i-am-a-segment/blabla/tralala Shows as a result: Segment: i-am-a-segmentURL: /urlsegments/i-am-a-segment/blabla/tralalaCatetory: tralala So what you think? Should I give it a try and test the cachig if it works ? categories-listtegories-listcategories-list'
  11. @fbg13 Trying your suggested approach showed properly the url segments. Now I would try to rething the template logic so that if a need be the segments work fine. @BitPoet You got straight to the point and the reason why I tried implementing the categories by a field in recipe-inner template - as I am expecting to have several cases where a recipe fals into different categories and would need to be listed when a request comes (eg. low sodium, salads, easy recipes etc.) So other than using urlSegments to filter the category, are there any other mechanisms that would allow me to get the name of the category from the url and use it as a filter criteria in my query? As of now the only filtering I would need would be by category as the rest of the website would be listed as a search result. As far as the url to access categories is not food.pw/recipes/category/subcategory but food.pw/category/subcategory I guess I should redo the 'category' template and add some logic there (if there are no subcategories in the url, then list the categories with images and links, but if there is an urlSegment - show filter results). It gets interesting, however it was proven that urlSegments work, so now it is up to me to find the best approach to make it work. Thank you all for the knowhow!
  12. @szabesz Yes, I just exported the whole profile which would allow me to upgrade easily my PW to 3.0.65 or downgrade if a need be. It all worked the same way it did on the localhost but not with the urlSegments. @BitPoet What you say makes perfect sense now and explains why it would not work in my scenario. Considering the fact, that I already have a page Recipe Categories which would point to food.pw/categories/ and just need to be able to browse to a specific category showing the pages that have it selected, would you suggest another approach other than creating the categories as parents and placing the recipes as children of them? I did a profile already that way and it worked just fine, but I was trying to extend my knowledge using the present approach. Thank you guys for sharing your experience. It means a lot to me! Even though PW has been flawless so far for my needs, I am not just trying to make the profile work but have some learning curve I could use in the future to extend my knowledge and have eventually one much smarter, simpler and cleaner sollution. P.S. Reading your suggested approach, I am afraid that I already gone far in developing the recipe-inner template which is assigned for every recipe and pulls up quite a lot of frontend formatting etc. so I won't be able to assign the category-list template to my recipes and break the functionality that is already at a final stage.
  13. Tried moving the profile to my real domain, but that does not change anything. On one side - I am glad as it is easier for me to work on my local server versus online but on the other end - the saga continues. Does anyone know if there are any requirements for apache/php modules in order to make the urlSegments to work? Or any information about the proper way of setting up templates and options would be good for starters. So far it was pinpointed that the $input->urlSegment1 & 2 does not get values of 'category' and 'bakery' while browsing the url: food.pw/category/bakery/ Regex allowing expression did not change anything as well.
  14. As far as I am still bumping my head against the wall I decided to give it a try by moving the profile to my actual domain. Doing so would allow me to eliminate a possible issue with the segments on local server and eventually demonstrate if a need be what is the setup, fields etc.
  15. Well I renamed the page name to Recipe Categories which points to /category/ but that did not change much the result. Do you know of any profile example I could have a look for filtering pages by a field value using urlSegment? As I checked the SkyScrapers but the buildings are organized differently and I do not find some logic similar to my case I could use. For sure I could switch the categories to become parents inside the Recipes and then just point to childrens but I would like to extend my knowledge on using urlSegments and that is why I did not organize it that way.
  16. @fbg13 Sorry, it was a typo as I was typing the code manually. The proper code is: <?php $segment1 = $input->urlSegment1; $segment2 = $input->urlSegment2; echo $segment1; echo $segment2; } ?> The url I am trying to access is: http://food.pw/category/bakery/ where I guess the $input->urlSegment1 should be 'category' and the $input->urlSegment2 should be 'bakery' which is what I need to run a query and show all the recipes which has the 'bakery' assigned in the recipe-inner template through field 'recipe_category' which is a Page reference (Page Autocomplete) pulling data from Categories page children. @Sérgio Jardim I tried using your suggested regex expression to allow the URL Segments and after refreshing the page I got the same reply: ProcessWire\WireInput Object () when trying to echo $segment1 & $segment2
  17. @fbg13 I have the following structure and templates; Recipes (recipes) - /recipes/ Recipe1 (recipes-inner) - /recipes/recipe1 Recipe2 (recipes-inner) - /recipes/recipe2 Recipe3 (recipes-inner) - /recipes/recipe3 Recipe4 (recipes-inner) - /recipes/recipe4 Categories (categories) - /category/ Category1 (categories-list) - /category/category1 Category2 (categories-list) - /category/category2 Category3 (categories-list) - /category/category3 Category4 (categories-list) - /category/category4 @Sérgio Jardim When I tried to print_r($input), I got this: ProcessWire\WireInput Object ().
  18. Ok. This time removed the if statement and tested the following code: <?php $segment1 = $input->urlSegment1; $segment1 = $input->urlSegment2; echo $segment1; echo $segment2; } ?> but it still shows no results...
  19. @fbg13 I used the following code to print the segments: <?php if($input->urlSegment1 == 'category' && $input->urlSegment2) { $segment1 = $sanitizer->pageName($input->urlSegment1); $segment2 = $sanitizer->pageName($input->urlSegment2); echo $segment1; echo $segment2; } ?> and it shows nothing for segment1 and segment2
  20. Ok, I tested the if-query for $input->urlSegment1 and found out that something gets wrong in there: <?php if($input->urlSegment1 == 'category' && $input->urlSegment2) { echo 'urlSegment statement works'; } ?> So nothing shows as a result. I attached a screenshot of the URL settings of the template. Anything else seems to stop the proper resolving. Could the reason of not working be the fact that I work on a localhost instead of having FQDN for proper resolving? P.S. I even tried to allow category, bakery and other category segments in the allow url segments field but still got nothing...
  21. Hello AndZyk. I must have changed name with title while trying to figure what is happening. So I changed the code to: <?php if($input->urlSegment1 == 'category' && $input->urlSegment2) { $name = $sanitizer->pageName($input->urlSegment2); $category = $pages->get("template=categories-list, name=$name"); if($category->id) { $q = $pages->find("template=recipes-inner, recipe_category=$category"); } } ?> And made sure that all template names are correct, however when I echo the $category it shows empty. It feels to me that $input->urlSegment does not get results. I have the tracy debugger installed and it shows no errors so I need to figure out what else I am missing. I tripple checked the urlSegment settings are enabled for 'category' and 'caegories-list' .. Will try to take it step by step and figure out what is stopping the urlSegment to resolve the proper name and assign it to the $category.
  22. Hello my friends. Today I started working on my recipe website again and it was the turn to show recipes (pages) that has a specific category assigned in a field. In my NowKnow project for categories I used a parent page where inside of it I had the children and everything seemed to be super easy. This time, however, I decided to change the approach so I created a parent page Recipe categories and assigned to it my 'category' template. Inside the parent I added a few categories that I want to be able to select via PageReferrence field 'recipe_category'. The parent template would show all the categories represented by a title and an image - that part is done and works fine. Now what I am trying to achieve is to have a few recipes having the 'recipe_category' field equal to Bakery for example, and then when I point to the category URL to get only the recipes that have Breakfast selected in. From what I know the perfect approach to achieve that would be to use $input->urlSegment as to select the name of the category from the URL and then filter the pages adding to selectors: recipe_category=$category. Following Ryans earlier instructions about the urlSegment and an example found here in the forum, I got this code to fit my fields names: <?php if($input->urlSegment1 == 'category' && $input->urlSegment2) { $name = $sanitizer->pageName($input->urlSegment2); $category = $pages->get("template=categories-list, title=$name"); if($category->id) { $q = $pages->find("template=recipes-inner, recipe_category=$category"); } } ?> After adding the code, I enabled the URL segments for both: 'category' and 'category-list' templates. Browsing the URL for the Bakery category: http://food.pw/category/bakery/ (the domain name is not a typo, but PW is on my local server) I was supposed to get the $category to get the value of 'bakery'. However instead of that I am getting nothing. What am I missing in the big picture as I am sure it is again something silly but I spent almost the whole day trying to figure it out and still got no progress? P.S. trying to change the urlSegment number to 3 did not help either
  23. 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
  24. <?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.
  25. 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.
×
×
  • Create New...