Jump to content

kathep

Members
  • Posts

    133
  • Joined

  • Last visited

Everything posted by kathep

  1. A quick callout in defense of us 'starters'! My current process before asking a question in the forum is to: 1. google the forums, if I find code: 2. test the code on my site, noodling around for a few hours usually. If I don't find code, or can't get it to work: 3. google php references (I'm new to php, but fine with html & css) 4. test code I found at php references, if that doesn't work 5. google pw forums again 6. ask question on the forums If there is something else I should be doing to avoid being typified as 'jumping in and expecting an answer' or being 'lazy' or 'impatient', please let me know! I think we have a great dev community here, and I look forward to one day knowing enough to help others. Please don't hate on newbies... we're trying. On another topic earlier in this thread... as for tech wars... I think this is an archetypal theme (battle to the death! Who! Is! Deadliest!) that will always make money, and is therefore never going away. The important thing is that we recognise it for what it is - a distraction - and work on feeding the good community vibe here in spite of such distractions.
  2. Oh wow, @horst. I had not heard of any of those links! Thank you for many future hours of geeky browsing
  3. @kongondo thanks for this little example of if {} else {} in action! I just used it for another situation. Very helpful.
  4. @LostKobrakai Thanks for the code and learning tips! I am using the API cheatsheet a lot, but I didn't know about the 'advanced' mode! That will be very helpful. I have more knowledge than the 'beginner' tutorials are suitable for, but not enough to understand much on the forum posts outside of 'getting started'. I think there is a big gap in documentation. That is why I keep posting long explanations of things I am learning! Hopefully it will help other tinkerers like myself some day. Thanks again Will play with this count code more.
  5. @Jan Romero your post helped me understand @LostKobrakai's better. I have replaced the minus signs with en dashes, thanks I would like to check whether I found some pages - now that I have added the remove($page), I do get some empty results. However, I have no idea how to check. Could you suggest a link for me to learn from, or some code?
  6. Thanks @LostKobrakai. I see how your code makes more semantic sense. However, I am stuck on finding this missing piece: "selector to get only pages for $category" Can anyone provide me with a clue to get closer to the code for this selector? I am looking for a selector that will find the value of the previous $category->title, and then return only the fields (design_technique->title and design_technique->book_section_reading_time->title) related to it.
  7. UPDATE: Duplicating output issue I've been working on this since my last post, and I have made some progress. Removed current page from pageArray thanks to @LostKobrakai. However, I've noticed a problem with my code that calls the readings. This output is being generated: The code is collecting all readings related to all all categories, and outputting the entire list under each category heading. Here is the incorrect code: $design_prin_rel = $page->design_principle_related; $readings_dpr = $pages->find("template=readings, design_principle=$page->design_principle_related"); if($design_prin_rel instanceof PageArray) { $dpr_heading = "<h3>On related design principles</h3> "; foreach($readings_dpr as $item){ $readings_test2_list .= "<p> '<a href=$item->url>" . $item->title . "</a>' " . "-" . $item->book_section_reading_time->title . "</p>"; } foreach($design_prin_rel as $item) { $read_test2 .= "<h4>" . $item->title . "</h4>" . $readings_test2_list; } } I know what's wrong with it, but I don't know how to fix it. Avoiding this problem was the reason I was trying to use getNext() and slice() initially, when I started this thread, but I didn't get so far with that experiment. Any suggestions of how I can get each (design_technique->title) and time (design_technique->book_section_reading_time->title) displayed to relate only to the category immediately displayed above it?
  8. One more related question: what is the best way to filter out the current page from the pageArray results? The code I'm using lists all readings in the category, including the current page. It would be better if I could filter out the current page from all results.
  9. UPDATE: Not resolved! It worked, mostly! The only thing stopping @nghi's code from working was a missing concat dot that @horst pointed out. Thank you all for your help. I am learning so much, and having so much fun.
  10. @Martijn Geerts ah yes, this is my probably-not-very-good way of writing 'If this page has something in the design_tech field, show the following code.' Not all pages with the 'readings' template have the design_tech field, and where it does not occur, I don't want the associated HTML to appear. If there is a better way to write this, please let me know! @horst I think we replied at the same time. I am now trying the code with the concat dot....
  11. Ah ok! Thank you @adrian and @nghi. But then for my next question... I find this solution doesn't work when I replace the placeholder text with correct code. This code: $read_test = ''; $design_tech = $page->design_technique; $readings_dt = $pages->find("template=readings, design_technique=$page->design_technique"); if($design_tech instanceof PageArray) { foreach($readings_dt as $item){ $readings_test_list .= "<p> '<a href=$item->url>" . $item->title . "</a>' " . "-" . $item->book_section_reading_time->title . "</p>"; } foreach($design_tech as $item) { $read_test = "<h3>On the same design skills</h3> <h4>" . $item->title . "</h4>" . $readings_test_list ; } } ... only outputs the last field and associated reading in the design_technique field. Like this: I want the code to show each of the three categories (Pantone, CMYK, RGB), and a list of every reading associated with that category. But I don't know how to tell the code to do this! What would be the best way to get each category to display with the associated readings (design_technique->title) and time (design_technique->book_section_reading_time->title) below it? I suspect this is really simple, just beyond my knowledge
  12. Hey all, I have a small problem. I am trying to output a formatted list of categories (fieldname & parent page are both called design_technique) from a Multipage array associated with the current page. I have got as far as showing two of the categories (see below): But when there are more than two categories in the multipage array, I get stuck. The code that works to get the first and second categories is this: $read_test = ''; $design_tech = $page->design_technique; if($design_tech instanceof PageArray) { foreach($design_tech as $item) { $read_test = "<h3>On the same design skills</h3> <h4>" . $page->design_technique->first->title . "</h4>" . "<p> Placeholder where article in this category should go. </p> <h4>" . $page->design_technique->getNext($page->design_technique->first)->title . "</h4> <p> Placeholder where article in this category should go. </p> "; } } For the third category output, I have tried slice() like this: <h4>" . $page->design_technique->slice(3, 4)->title . "</h4> <p> Placeholder where article in this category should go. </p>"; And I have also tried looping getNext() like this: <h4>" . $page->design_technique->getNext($page->design_technique->getNext)->title . "</h4> <p> Placeholder where article in this category should go. </p>"; Neither has worked. In other situations i have used implode() to generate a list of items in a pageArray, but since I want the HTML formatting, and eventually more php calls where the placeholder text is right now, I am stuck. Does anyone have any idea of how to get this code to work?
  13. Ok, good to know. And thank you for explaining what is wrong with my code, and how to shorten it. It seems every time I have a problem in processwire I discover many more cool things than I originally hoped for. @Jan Romero ah, ok. Good to know. I guess me and @horst have another Stack Overflow link to bookmark.
  14. Hey @horst Oh wow, you are thorough! I only tried your first example, the long one. Honestly, I did not feel confident to try the second one, as I find the long version hard to understand, let alone the second one with the shorthand! Your latest example with even more markup helps me understand the purpose of each line. When I have some experimenting time, I will play around more with this code. One day I hope to understand all of it.
  15. RESOLVED Here is the code I used to fix the duplicate problem. It is mostly @horst's code suggestion from above, with something added (from this stackoverflow post) and something taken away. // beginning of new design category code if($design_technique instanceof PageArray) { // create array for collecting output $outItems = array(); foreach($design_technique as $test_skill) { // array collecting categories $alreadyFoundCategories = array(); foreach($test_skill->design_skill_category as $example) { // add it to the list $alreadyFoundCategories["{$example->title}"] = $example->title; // collect for output $outItems[] = $example->title; } } // create the output $import_skill .= implode(" / ", $outItems); $import_skill_clean .= implode(' / ',array_unique(explode(' / ', $import_skill))); } //end of new design category code I didn't know about array_unique or implode then explode tricks until this afternoon. Another lesson in php from processwire implementation. I am cobbling together code from various sources until it works, without really understanding _how_ it works yet. Please forgive ugly syntax and nonsense in my code, and feel free to offer improvements.
  16. Hey @horst, So I finally tested this out. It works, sort of. With the suggested code, I get exactly the same output as with my original code... duplicates from the 'design_skill_category' field that I am trying to avoid. I guess that this snippet is not doing what it is commented to do: // is already processed, so skip this one if(isset($alreadyFoundCategories["{$example->title}"])) continue; But this php is far more advanced than my ability, so it is just a guess! If anyone can notice a change to @horst's code above, or suggest another direction for me to research, please let me know!
  17. Oh wow, thank you @Horst! This is just the kind of thing I was looking for. I will test it out and let the list know if/when I have success. Thanks again!
  18. Narrowing down the problem Whoa, looking back on this code, it is confusing! And I'm the one who wrote it! I will try to write the problem I have in a clearer way. Using php.net and googling the forums a lot, I have identified a possible solution. I don't know how to implement it myself, but hopefully someone will have an answer... 1. The problem Narrowing down (and clarifying) the code involved in the problem: // calls the MultiPage field book_title_from_list (which references reading_books.php) $reading_books = $page->book_title_from_list; // calls the MultiPage field design_technique (which references design_technique.php) $design_technique = $page->design_technique; // for every instance of a design_technique, show a list of every category associated with that technique // shows each list one after the other if($design_technique instanceof PageArray) { foreach($design_technique as $test_skill) { $import_skill .= " > " . $test_skill->design_skill_category->implode(" / ", "title") ; } } // this is its own call because I add some other arrays (that are not relevant to this example, so not shown here) $reading_category = $import_skill ; // if a book title has been selected, show the array $reading_category in main content area if($reading_books instanceof Page) { $content = $reading_category; } I have commented it as best I know how. Please improve it if you notice any silly errors! The incorrect code is this: if($design_technique instanceof PageArray) { foreach($design_technique as $test_skill) { $import_skill .= " > " . $test_skill->design_skill_category->implode(" / ", "title") ; } } I see now that this code is kind of dumb. The code itself tells me the output will not be what I want. 2. The potential solution I think I need to break it down into two chunks, something like this: // make a list every design_technique selected (only for calculation, not for output) $list = *some code* // identify every design_skill_category associated with $list if($list *some code*) { *some code* { $import_skill .= " > " . *some code*->design_skill_category->implode(" / ", "title") ; } } Hopefully such code (when gaps are filled in) would avoid repeated output of design_skill_category items when they are referred to by multiple design_technique items. Can you offer a link to a php reference or tutorial that could get me another step closer to filling in the blanks? Or even a solution?
  19. Ah yes, I have (thankfully) already discovered these ones. I am so grateful to the dev community for making them!
  20. Hey all I recently resolved a problem displaying relational category information (see here). I now have another challenge using similar code. I have set up a sort of 'breadcrumb of categories' for certain items. It refers to these templates and fields: design_skill_categories.phptitle design_technique.phpdesign_skill_categories (a Multiple Page field referencing design_skill_categories.php) title readings.phpdesign_principle design_technique (a Multiple Page field referencing design_technique.php) psychology_topics The following code works great when there are only a few items selected in the design_technique field: $subject = ''; if($page->psychology_topics instanceof PageArray) { foreach($page->psychology_topics as $test) { $subject = " > " . $page->psychology_topics->implode(", ", "title"); } } if($page->design_principle instanceof PageArray) { foreach($page->design_principle as $test) { $subject1 = " > " . $page->design_principle->implode(", ", "title"); } } //design_skill_category to show for each design_technique $design_technique = $page->design_technique; if($design_technique instanceof PageArray) { foreach($design_technique as $test_skill) { $import_skill .= " > " . $test_skill->design_skill_category->implode(" / ", "title") ;} } if($design_technique instanceof PageArray) { foreach($page->design_technique as $test) { $subject2 = " > " . $page->design_technique->implode(", ", "title"); } } $reading_category = "<p><strong>Subject:</strong> " . $page->reading_categories->title . $subject . $subject1 . $import_skill . $subject2 . "</p>"; if($reading_books instanceof Page) { $content = $reading_category; } When there are only a few techniques, this is the output I get (which is just what I want): The basic format is 'level one sorting > level two sorting / separated by backslashes > level three sorting, separated by commas'. However, when a page using the template readings.php has several techniques associated (field: design_technique) that in turn have several categories (field: design_skill_categories), it doesn't work. See below: In the second example, my system is broken and changes to: 'level one sorting > level two sorting / related to design_technique 1 > level two sorting / related to design_technique 2 > level two sorting / related to design technique 3 > level three sorting, design_technique 2, etc'. I would like to alter my code so that all the categories (field: design_skill_categories) related to all of the techniques (field:design_technique) display in between a beginning '>' and an end '>', and each category only displays once. Do any of you know a way to write the code to achieve this? I hope I have been doing things the long (and probably hard) way, and that someone has a relatively easy solution. *crosses fingers*
  21. Aaah! I can't believe I missed this for a week! This will save me so much time! I'm constantly surprised by how many extra pages I'm making as my PW site develops. All in the name of scalability.
  22. Ok, thanks for confirmation! It seems strange to me, but then I know very little about server performance. Also good to have confirmation of Transmit's robustness. I really like it in general. I'll get on to my site host and see if there is something that can be done.
  23. Nerdy fun fact update: I've discovered there's a two minute lag between when my sitehost registers main.css as being updated, and when the changes are visible in a browser on multiple devices. I didn't know such a lag could be possible, but now I do. How did I find this out, you ask? By live updating my main.css as suggested above, refreshing the online file viewer provided by my site host, then refreshing various browsers repeatedly to find the soonest possible time that the changes are visible.
×
×
  • Create New...