Jump to content

kathep

Members
  • Posts

    133
  • Joined

  • Last visited

Everything posted by kathep

  1. Good to know. I haven't heard of forklift before. I'll check it out. Thanks @adrian and @macrura for the forklift tip.
  2. OMG, mind blown! I love this idea. Mind blow again!! This is so awesome. I am off to change my prefs...
  3. Thanks @LostKobrakai and @pwired. You have given me some good ideas. Ok, good to know Yeah, I'm developing a website that is hosted at siteground.com, and working on it remotely on a MacBook Air (10.9.3). I prefer to work online rather than using mamp, partly because I get to observe how 'heavy' my site is as I build. I've had the unfortunate experience of building a website using mamp that was way too heavy - despite all the usual optimization tricks. I don't want to repeat that. I actually like the version control FTP gives me (when it works). Actually, its more about 'my FTP client tells me my remote css file has successfully been updated, but no browser displays that it is up-to-date'. I have noticed the website is also drawing from the out of date css file on browsers on my phone. Yes! This test solved the mystery. It turns out the culprit is my FTP client (I'm using Transmit). It displays a successful upload and a 'date modified' time that is current (on the remote server) for an old version of the main.css file. Grr. Will use a different FTP client and that *should* fix it. This turns out not to be a PW question at all, but I at least hope it will help another noob another day.
  4. Thanks for the quick suggestion, @LostKobrakai . Yes, it could be something to do with the .htaccess file. With my current (small) amount of knowledge, I'm scared to touch the .htaccess file right now. But I'll do some googling and try to prepare myself to tackle it. This is something else I may need to check. It seems unlikely though, as this server (I'm using siteground.com) hasn't had any issues with the many css file uploads I've done on it before. Thanks again! If anyone else has further suggestions on how to tackle potential caching issue in htaccess, please let me know.
  5. Hey all I have a frustrating issue with lagging display of css changes in my PW install. When I change code in main.css and upload the file via FTP, sometimes the css styles are updated in the browser display, and sometimes not. It takes about 10 times of uploading main.css for the browser display to reliably change to reflect the changed css styles. Steps taken each time: css file is opened css code is changed the css file saved locally the css file has uploaded via FTP correctly refreshed PW site in the browserif changes showed, breathe sigh of relief if no changes shown, upload via FTP again refreshed PW site in browser ** repeat indefinitely ** This is happens in multiple browsers (Chrome & Firefox, latest versions), including: when caching is turned off in the browser when all browsing history is cleared when PW site is re-opened in a browser it has never been viewed on before I have only ever experienced this mysterious refresh behavior specifically with the CSS file in PW. All other files in PW refresh fine, and I have never had this refresh problem with a CSS file on another site. However, I have never worked with css on a PHP based site, so I'm wondering if this is the issue. I have tried changing the code calling the css in _main.php from the default: <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css" /> to the following (based on this advice on stackoverflow, when I thought it could be a Chrome issue): Attempt 1 <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css?v={random number/string}" /> Attempt 2 <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css?v=<?=time();?>" /> Nothing worked. Is there something about how PHP or PW handles CSS files that I don't know? Some internal caching of css in PW that I need to reset? One option to resolve this is to use @nico's Template File Editor module to make changes to the files live. Because i am old school, I really don't want to do that. I really prefer to edit files locally and upload them. Any suggestions to this css refresh problem, pro PW users?
  6. Yes, I am learning PHP quite fast using PW. I didn't know any before last week I think I found PW by googling for a lightweight CMS. The bloated options of the big, popular CMSs, and the limitations of certain small open source CMSs were unsuitable for my needs. I hoped there was something better. I find developing in PW quite addictive. I'm not sure if its the full control of information architecture, or how much fun php is, or the ease of use of the PW API. Do others find it addictive? Anyway, I am having a lot of fun with it.
  7. Ah, @horst thank you! You have stopped many hours of frustration! @nico, I wanted the output to look like this: which it now does, thanks to @horst reminding me of the concat dot in your original solution. BTW, I am very grateful to have access to such a helpful community of processwire fans. This just adds to the already very awesome experience of using processwire.
  8. I am trying to output my first instance of multiple fields from a pagearray, and only have partial success. My problem involves the following fields and templates: assignment.phpreadings_from_list readings.phptitle book_section_reading_time Using either of the following code options: Code option 1, adapted from @teppo's solution here: // using pages->find to display muliple values from a PageArray // only one selection displays though $reading = $page->reading_from_list; $reading_w_heading = ''; $reading_w_heading = $pages->find(); foreach ($reading as $read) { $reading_w_heading = "<p><a href='$read->url'>" . $read->title . "</a> - " . $read->book_section_reading_time->title . " of reading</p>" ; } $content = <h4>Read:</h4>" . $reading_w_heading; ​Code option 2, adapted from @nico's solution here: $reading_w_heading = ''; $reading = $page->reading_from_list; if($reading instanceof PageArray) { foreach($reading as $read) { $reading_w_heading = "<p><a href='$read->url'>" . $read->title . "</a> - " . $read->book_section_reading_time->title . " of reading</p>" ; } } $content = <h4>Read:</h4>" . $reading_w_heading; Outputs this result: Despite more than one item selected in the field readings_from_list: I suspect this has a really simple solution, but my knowledge is so basic that I can't figure it out. Frustrating! Could someone point out to me where I am going wrong? Note: I don't want to use echo because I am using _init.php and _main.php from the PW_default template, and like this system very much. However, when I echo anything, it appears above the _main.php content (and therefore above my main navigation) - suboptimal.
  9. Ah cool. Thank you for suggesting a more correct alternative. I am still learning about echo. I also like the 'else' option - this is a very front end user friendly option! I will make use of it. In case you are interested, I am using these things here.
  10. Ah, I see , thank you for the further explanation. Here is my write-up of steps for displaying relational data for absolute beginners, based on what the steps I have taken to fix my problem. Please chip in with corrections if any of you know a better way! Displaying Relational Data from another page, using fieldtype Page and Input Field Type Single page. Original problem: Steps to fix: Change field course_name_from_list to Single page (choose option: Single page (Page) or empty page (NullPage) when none selected). Change $sidebar code from this: $course_w_heading = "<h4>Course: " $page->course_name_from_list . "</h4>"; $sidebar = $course_w_heading; // I made an array and added it to $sidebar because I had extra arrays to add, which I have left out here for the sake of keeping the examples simple. to this: // array 1: calls the Page field $course = $page->course_name_from_list; // array 2: includes fields from $course and formatting I want outputted on page $course_w_heading = "<h4>Course: " . $course->course_number . "<br>" . $course->title . "</h4>"; // call sidebar as blank - I'm not sure why this is necessary $sidebar = ''; // if the Page field has a selection, output if($course instanceof Page) {$sidebar = $course_w_heading ; } It looks simple, and it is! However, I had many headaches and false starts getting here. I hope documenting this can help save other beginners some time.
  11. Hi @kongondo, and thank you for your long-windedness. It really helps me to learn. The field course_name_from_list is currently a Multiple page field. I would prefer it to be a single page field, but when I choose either option 'Single page (Page) or boolean false when none selected' or 'Single page (Page) or empty page (NullPage) when none selected', my page returns a lot of errors, like this: I don't have enough knowledge to understand these errors, so I got scared and returned the field setting to Multiple page. UPDATE: Resolved I just started working through the errors to try to fix them myself. I removed a '->first()->title' from an instance of $page->course_name_from_list and that removed all errors. Now my page works, and the code provided by @nico works! It was a simple fix. I'll write up my steps for an absolute beginner and post them below. Thanks @kongondo! Thanks @nico!
  12. UPDATE: Improving my code Hello all I am working hard to understand @nico's code posted above. I have changed my code to be closer to his example: $course = $page->course_name_from_list; $sidebar = ''; if($course instanceof Page) { $sidebar = $course->course_number . " " . $course->course_name ; } echo $sidebar; However, this code does not display a sidebar. Any suggestions? My best guess is that if($course instanceof Page) is returning a null value for some reason. My next step will be to test with different Input Field Types. I will keep working on this, and if anyone has another suggestion, please let me know!
  13. Hello @nico and all I have adjusted your code to fit my page. I only used your second example, because there will only ever be one course selected in the field course_name_from_list, and there will only be one entry in field course_number associated. Perhaps I have broken something in the process of adapting the code... //sidebar variables $course = $page->course_name_from_list; // the page inputfield returns a page object if max=1, or a PageArray, if max. is above $course_number_test = ''; if($course instanceof Page) { $course_number_test .= $course->course_number . " " . $course->title; } echo $course_number_test; $course_w_heading = "<h4>Course: " . $course_number_test . "<br>" . $page->course_name_from_list->first()->title . "</h4>"; // Primary content goes here $sidebar = $course_w_heading . $course_section; I changed $content in your example to $course_number_test (for testing purposes) because $content is already on use in the page, and I want the course number to appear in the sidebar. Adding the code listed above to the assignment.php template did not change the output result. Any ideas as to why that is? What am I missing?
  14. Ah, thank you! I will try it out and let you know how I get on.
  15. Hello all, and Merry Christmas! i have a seemingly simple problem that I don't know how to fix. I have seen a range of posts on this topic (this one and this one were particularly helpful) and tried to combine them to fit my use case, but so far no luck. I am a beginner with php. The problem includes two kinds of pages, with the following associated fields: course.phpcourse_name course_number assignment.phpcourse_name_from_list i have a list of assignments, and a list of courses, each assigned one of the above templates. I am using the 'course_name_from_list' field to associate each assignment with a particular course. It is a page fieldtype referencing my course pages (which are stored at '/teaching/courses'. My question is: How do I get each assignment page to display the course_number on the course page associated with the selection in 'course_name_from_list'? My best guess so far is like this: $call_courses = $pages->get('parent=/teaching/courses'); $get_course_number = $course->course_number; $content = $get_course_number . " " . $page->course_name_from_list But I am doing something wrong, because this does not display the course number! Does you have an idea of how I can fix this code to get the result I want?
  16. @adrian Thanks! I agree, it does look more confusing to have multiple = on one line, but its helpful to me to know that it is legitimate markup.
  17. @BernhardB Ah, thank you for your many tips! I am learning fast by doing things wrong I am trying your improved code suggestion now... UPDATE: It worked! Successful result: Below is a breakdown of the steps I took in very simple terms for other beginners to follow (all credit to previous posters, especially @Horst and @BernhardB - you are truly patient ). Steps for creating random quote/text selection from a large pool (for an absolute beginner) All steps are completed through the ProcessWire admin panel, unless otherwise stated. These steps assume you are using the _main.php and _init.php files in your templates. Build a page called tools. This serves as a parent for stuff that is not used to be displayed directly in the frontend. Assign this page the pw_default template. Set the page to hidden. When saving this page, choose 'save + keep unpublished'. Create a new template called quote_category. This template only needs one field: title. Later, you will use the title field of this template to enter categories you want to use to classify quotes. Note: this is different to @horst's suggestion of a generic category field only for scalability - if you need to make other categories for other types of information in the future, and don't want them both to be called by the same function. In the code editor of your choice, create a file called quote_category.php. In the body of the file, enter: <?php // quote_categories.php template file Save this file to your computer. Using an FTP program, upload this file to your processwire installation at: site/templates/. Create a page under tools called quote_categories. This serves as parent for the categories you use to classify your quotes. Assign this page the pw_default template. Set the page to hidden. When saving this page, choose 'publish'. Under the page quote_categories, create child pages. Assign each child page the quote_category template. In the title field of each new child page, enter the name of one category you need. For every child page, set the page to hidden. When saving each child page, choose 'publish'. Create as many child pages as categories you need. Create some fields to be used on a new template (see next step): field label: Quote text field name: quote_text field type: textarea or text (depending on how long your quotes are, and how much formatting they require) field label: Quote Author field name: quote_author field type: text field label: Quote Category field name: quote_category field type: page Note: for this field, there are extra settings required - you can find them under the 'Input' section of field options. input field type: ASMselect* parent of selectable pages: /tools/quote_categories Any other field you need. For example, I have a quote_reference field to cite where the quote came from. This is not necessary though. Create a new template called quotes. Add the templates you just created to this template: quote_text, quote_author, quote_category and any others you made. In the code editor of your choice, create a file called quotes.php. In the body of the file, enter: <?php // quotes.php template file // Primary content goes here $content = "'" . $page->quote_text . "'". "—". $page->quote_author . "<br>" . "$page->quote_category"; Save this file to your computer. Using an FTP program, upload this file to your processwire installation at: site/templates/. Create a page under tools called quotes. This serves as parent for all single quote pages. Under the page quotes, create child pages. Assign each child page the quote_category template. When saving each child page, choose 'publish'. Create one child page for every quote you have. In an FTP client, download the template where you want a random quote to appear. In your code editor of choice, open the template where you want a random quote to appear. Enter the the following code: $quote = $pages->find("parent=/tools/quotes, quote_category.title=category1|category2")->getRandom(); //add nice formatting $quote_w_heading = "quote: '" . $quote->quote_text . "' —". $quote->quote_author; In the above example, replace the text 'category1|category' with the name of the category/ies you want to display a quote from. Then, at the $content or $sidebar function (or wherever you want your quote to display), add the following code to the end of the string: . $quote_w_heading So the $content string should look something like this: // Primary content goes here $content = $course_number_w_heading . $course_summary_w_heading . $recording . $quote_w_heading; Save your template file. Upload it back to to site/templates/ In your browser, view a page that uses the template you just changed. Refresh the view, and marvel at your new random quote appearing! Now that I have written out all these instructions, I see that this is perhaps not a beginner project. More experienced people, please offer corrections to any steps you see that could be improved. Thanks again all for your help!
  18. Ah @BernhardB, thank you! I missed your post, so thanks for reminding me. I have corrected that problem, but now I have another challenge... The page displays, but where I hoped the quote would appear, a number appears instead. Here is the code: $quote_w_heading = "Quote goes here: " . $quotes = $pages->get("/tools/quotes/")->find("quote_category.title=life")->getRandom(); // Primary content goes here $content = $course_number_w_heading . $course_summary_w_heading . $course_resources_w_heading . $course_readings_w_heading . $course_objectives_w_heading . $grading . "<h2>Getting Help</h2>" . $remind . $equipment . $success . $ability . "<h2>Conduct</h2>" . $honesty . $recording . $quote_w_heading; And here is what displays: Numbers also appear on my quote pages where the 'quote_category' fields should display: Perhaps I need to tweak something in my code, but I'm not sure what. Anyone see something suspect in there?
  19. Thanks for the quick reply @Horst. I think the problem must be on line 167 (the new code to add random quote), because the page works fine without that new code. I use Chocolat for writing code, and I really like it. It has syntax markup, and all looks fine... see below: Start of course.php code: In between there is nothing much - more calls to html. End of course.php code: I am using _init.php and _main.php from the default PW template for most of the markup. I am a little embarrassed to show my code, as I think this is not the best way to make a template. However, it has worked so far, so I am hesitant to change it. Do these screenshots help clarify the problem with my code?
  20. Hey all, I have successfully made the quote categories and added about 100 quotes. The new 'tools' part of my page tree now looks like this: I added the following code to my course.php template (as recommended by @horst): $quotes = $pages->get->("/tools/quotes/")->find("quote_category.title=life")->getRandom(); The only thing I changed was changing 'category 1' to 'life' - this is one of my quote categories. Now I get the following error: I'm new to php and can't figure out what it means. Does anyone have and idea how I can resolve this?
  21. Wow, thank you so much everyone. Thank you especially @horst and @ivan gretsky. I found the video really helpful for understanding what the page field does. And @horst your detailed instructions are just what I need as a beginner. I have followed your steps @horst, and all went well until I added the quote_category field to the quotes template. The only difference between what I have done, and what you have suggested in steps 1-3 is that I have named the parent folder for the categories as 'quote_categories'. Next problem... I have created a field called 'quote_category' and assigned it a type of 'page'. When I assign it an Input Field Type of 'AsmSelect', and choose 'quote_categories' as the Parent of selectable pages, I have a problem. When entering text into my quotes template, for the 'quote_category' field I get a drop down list that only contains the text '1051' (see screenshot here). UPDATE: Resolved I think '1051' was showing up in the dropdown list because I had not published my quote_categories child pages. When I published them, they showed up in the drop down list. Other beginners take note! I will keep you updated on how I go with this random quote display exercise. Stay tuned!
  22. I am setting up a new processwire site (kathep.com/cms), and have a problem I can't find a solution to on the forum so far. I would like the footer of one of my templates (course.php), to display a random quote in a specific category, from a collection of quotes. I currently have the quotes stored in a text file, and have set up four fields in processwire to take the information (quote_text, quote_author, quote_category, quote_reference). My questions are: 1. What is the best way to store the quotes in processwire? I'm not sure if its best to create an individual page for each quote, or to shell out for protools and store them in a table. I saw this example from Sinnut on this thread which looks good to me: But as I'm a beginner, I'm seeking advice of someone with more expertise! Would this structure suit my use case? 2. What is the best way to allow quotes to be stored in multiple categories? Ideally I would like to be able to select multiple categories for some quotes. Would this best be done in with check boxes? I'm not sure. 3. In my course.php file, what is the best way to call a random quote from a specific category? Thank you for reading this, and I hope someone can help.
×
×
  • Create New...