John W.

Members
  • Content count

    46
  • Joined

  • Last visited

Community Reputation

17 Good

About John W.

  • Rank
    Jr. Member
  • Birthday June 30

Profile Information

  • Gender
    Not Telling
  • Location
    Florida, USA

Recent Profile Visitors

1,176 profile views
  1. SYNOPSIS A little guide to generating an sitemap.xml using (I believe) a script Ryan originally wrote with the addition of being able to optionally exclude child pages from being output in the sitemap.xml file. I was looking back on a small project today where I was using a php script to generate an xml file, I believe the original was written by Ryan. Anyway, I needed a quick fix for the script to allow me to optionally exclude children of pages from being included in the sitemap.xml output. OVERVIEW A good example of this is a site where if you visit /minutes/ a page displays a list of board meetings which includes a title, date, description and link to download the .pdf file. I have a template called minutes and a template called minutes-document. The first page, minutes, when loaded via /minutes/ simply grabs all of its child pages and outputs the name, description and actual path of an uploaded .pdf file for a visitor to download. In my back-end I have the template MINUTES and MINUTES-DOCUMENT. Thus: So, basically, their employee can login, hover over minutes, click new, then create a new (child) record and name it the date of the meeting e.g. June 3rd, 2016 : --------------------------- OPTIONALLY EXCLUDING CHILDREN - SETUP Outputting the sitemap.xml and optionally excluding children that belong to a template. The setup of the original script is as follows: 1. Save the file to the templates folder as sitemap.xml.php 2. Create a template called sitemap-xml and use the sitemap.xml.php file. 3. Create a page called sitemap.xml using the sitemap-xml template Now, with that done you will need to make only a couple of slight modifications that will allow the script to exclude children of a template from output to the sitemap.xml 1. Create a new checkbox field and name it: sitemap_exclude_children 2. Add the field to a template that you want to control whether the children are included/excluded from the sitemap. In my example I added it to my "minutes" template. 3. Next, go to a page that uses a template with the field you added above. In my case, "MINUTES" 4. Enable the checkbox to exclude children, leave it unchecked to include children. For example, in my MINUTES page I enabled the checkbox and now when /sitemap.xml is loaded the children for the MINUTES do not appear in the file. A SIMPLE CONDITIONAL TO CHECK THE "sitemap_exclude_children" VALUE This was a pretty easy modification to an existing script, adding only one line. I just figure there may be others out there using this script with the same needs. I simply inserted the if condition as the first line in the function: function renderSitemapChildren(Page $page) { if($page->sitemap_exclude_children) return ""; ... ... ... THE FULL SCRIPT WITH MODIFICATION <?php /** * ProcessWire Template to power a sitemap.xml * * 1. Copy this file to /site/templates/sitemap-xml.php * 2. Add the new template from the admin. * Under the "URLs" section, set it to NOT use trailing slashes. * 3. Create a new page at the root level, use your sitemap-xml template * and name the page "sitemap.xml". * * Note: hidden pages (and their children) are excluded from the sitemap. * If you have hidden pages that you want to be included, you can do so * by specifying the ID or path to them in an array sent to the * renderSiteMapXML() method at the bottom of this file. For instance: * * echo renderSiteMapXML(array('/hidden/page/', '/another/hidden/page/')); * * patch to prevent pages from including children in the sitemap when a field is checked / johnwarrenllc.com * 1. create a checkbox field named sitemap_exclude_children * 2. add the field to the parent template(s) you plan to use * 3. when a new page is create with this template, checking the field will prevent its children from being included in the sitemap.xml output */ function renderSitemapPage(Page $page) { return "\n<url>" . "\n\t<loc>" . $page->httpUrl . "</loc>" . "\n\t<lastmod>" . date("Y-m-d", $page->modified) . "</lastmod>" . "\n</url>"; } function renderSitemapChildren(Page $page) { if($page->sitemap_exclude_children) return ""; /* Aded to exclude CHILDREN if field is checked */ $out = ''; $newParents = new PageArray(); $children = $page->children; foreach($children as $child) { $out .= renderSitemapPage($child); if($child->numChildren) $newParents->add($child); else wire('pages')->uncache($child); } foreach($newParents as $newParent) { $out .= renderSitemapChildren($newParent); wire('pages')->uncache($newParent); } return $out; } function renderSitemapXML(array $paths = array()) { $out = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; array_unshift($paths, '/'); // prepend homepage foreach($paths as $path) { $page = wire('pages')->get($path); if(!$page->id) continue; $out .= renderSitemapPage($page); if($page->numChildren) { $out .= renderSitemapChildren($page); } } $out .= "\n</urlset>"; return $out; } header("Content-Type: text/xml"); echo renderSitemapXML(); // Example: echo renderSitemapXML(array('/hidden/page/')); In conclusion, I have used a couple different processwire sitemap generating modules. But for my needs, the above script is fast and easy to setup/modify. - Thanks
  2. Adrian nailed it. Thanks for your help/input @abdus
  3. Exactly what I was looking for. That worked @adrian You provided a great solution that works. I would have never thought of $item->{$field->name} as storing the value of the field. The way I was originally thinking, in pseudocode was something like: $all-repeater-fields = $page->my_repeater->getchildren(); foreach($all-repeater-fields as $a-field) { echo $a-field->name; echo $a-field->value; } Could you also guide me into a direction in the PW docs or method in which you came across this? It seems little things like this, I dig into the documentation and API reference, and just can't find good examples/explanations for these types of questions. I try using var_dump() and the docs to try to 'connect' the dots, but something with the way I'm researching just isn't 'clicking'. The idea of $item->{$field->name} holding the value for the field would have never crossed my mind. Thanks so much for the assistance --
  4. I've been trying to figure a way to output the values of several fields within a single repeater using a foreach() without having to reference the name of the fields. Typically, for repeaters, I understand you would do foreach($repeater_field as $afield) { echo $afield->fieldname_a; } pretty straight forward. Anyways, what I'm doing is using a single repeater as just a container for other fields. I've tried using $page->my_repeater->getArray(), then looping through the array, and all sorts of methods, without luck. It seems I must specify the field name for output. For instance, my (single) repeater is set up to hold a few different fields: my_repeater field_a field_b field_c Trying to output it using something like this: foreach($page->my_repeater as $afield) { echo $afield->value; // I'm not wanting to have the reference the field name e.g. use $afield->field_a } Any suggestions?
  5. I know the point of PW forums is to discuss PW. I was just wondering if any consideration can maybe given to set up maybe a forum section called 'Front End Frameworks & PW', and maybe just a couple subsections like 'Bootstrap' and 'Zurb Foundation', (just maybe 3 of the most popular frameworks), to discuss questions integrating those with PW?
  6. I'm working on a site where I need to output data for a table. I looked at the Matrix plugin, but, I don't think it does exactly what I want...since my particular table is split into colspans i.e. Direct, Maternal, Carcass, and $Index An example of the table output is attached. I've pondered using 3 repeaters for the first column titled, EPD, Acc and %Rank. Each one of these repeaters would have the fields for CE, BW, WW, YW, MCE.... The last thing I want is to have to create a very long list of inputs vertically down the page for each field in the back-end for my client. Any PW gurus here, maybe help me out? If there is absolutely, no alternative to make input simple for my client, let me know if I have to buy ProFields. thanks mucho!
  7. Thanks. I fresh installed 3.0.42 on my local system. I then exported the database from a previous site running on 3.0.42. Next, I imported the database, deleted templates/fields that I not re-occuring across projects, installed my modules, setup my custom ckeditor .js and .css files. Finally, I ran the ProcessWireUpgrade to upgrade the local site to 3.0.62. It all looks good. From here out, I'll run ProcessWireUpgrade, then use the profile export module when setting up a new site. Thanks for the help! Btw, when I set up on a remote site, I always use the PW installer. After that I import JUST the db from my local install, ftp upload the templates folder and lastly use the api to set a new password for the admin account for login. - never had an issue.
  8. Question 1 I recently installed PW 3.0.62 for a new site and also have sites running older version of PW 3.x. Can I export the database on an older version of PW 3.x and import it to PW 3.0.62 without any issues? Question 2 (This is kind of alternative to the above for long term use - and maybe a better solution...) On the sites I've previously built I have templates (home, basic-page, contact) and fields that I commonly use, such as business_name, phone_1. The last site I built is running PW 3.0.42. I was considering cloning this into a local site and running the upgrade module to bring it up to PW 3.0.62. From there on out when I start I new project I could just run the PW upgrade module, copy the folder to the location for the new project and duplicate the database using the new projects name. So basically, I'll always keep a "blank slate" site that I can just run the PW upgrade on, then duplicate into a new project. This would cut down on the work and time spent having to re-create these common fields, that I use. From there, I would just add fields, templates, etc, specific for the new website project. Is this a sound approach to speed up development?
  9. I just posted a question about moving PW from a resting domain to a production domain, after consideration I figure I would create a new post for a second question I have. I noticed the coming feature of client size image resizing. This will be really helpful, as I have some clients on a Satellite connection. I'm telling you, them trying to upload 15MB images, or them getting them straight on batch resizers (or Photoshop) to resize before upload is a real chore. Needless to say, Ryan has been doing an excellent job addressing this. My question, is that I have several clients on PW 2.x thru 3.x. Is there a really good guide on steps that I need to take to update the core to take advantage of the features of new releases? Are their perils to look out for? Yeah, after developing several sites, I feel a bit silly about asking this one, but, the docs doesn't seem to be clear in a "general" sense of upgrading the core across all versions. Thanks everyone for your time and assistance.
  10. Summary: If I have a site sitting on a server called testing.com, then on the server change it to mycompany.com, do I have to modify any settings in ProcessWire? After building several processwire for clients, the one question that I haven't had is about moving a processwire site from an old (temporary) domain to a new domain. For instance, I typically setup development sites for clients and register a temporary domain (and lock with a password). For instance, thee client can go test.com and get all their content finalized, change wording, add news, swap out photos -- everything to make the site production read. Next, on my hosting account I can have testing.com renamed to theircompany.com - and change the nameservers. A simple question here. If I have a hosting company rename the account from testing.com to theircompany.com, change my nameservers whereas going to theircompany.com loads the production site, Is there anything I need to change in the processwire configuration or in the PW database? In the past, I've just manually copied the site, and fresh-installed PW, and imported the data. Seems like a lot of hassle. I have a second part question about updating the PW core, however, after consideration I'll post it as a new topic.
  11. Also check the permissions on your /site/assets/files folder. Should be 755.
  12. I ran into an issue a Wednesday, where a client on satellite getting logged out every few seconds. The above fixed it, however, I had to change the config.php file in the /wire/ directory. I didn't see the setting in the /site/config.php, so I assume that it's due to changes in PW since this post was originally written. Thanks for the tip @adrian
  13. Thanks, that fixed it. There was a space between mystyles: and /site/modules/ ... the the correct syntax mystyles:/site/... and not mystyles :/site/... A note for other readers, the Styles drop-down wasn't displaying anything after the change quoted above. However changing the style name in the mystyles.js file from: CKEDITOR.stylesSet.add( 'default', [ to: CKEDITOR.stylesSet.add( 'mystyles', [ fixed the issue of the styles list being empty. @Macrura - thanks!
  14. Thanks adrian & Robin S for the additional information.
  15. This question has probably been beaten to death - think I'm approaching this wrong. Anyway, I've got a textarea input field that uses ckeditor. Under the fields Input section I managed to add my custom style sheet in the 'Custom Editor CSS File (regular mode) section for instance: /site/templates/css/ckeditor.css This seems to work fine. What I'm trying to do now is add a custom style to the ckeditor styles menu, for instance, called .green_button (p.s. in the ckeditor styles.js I added this to the inline section : { name: 'Green Button', element: 'a', attributes: { 'class': 'button' } }, Ok, onto the problem... I notice that PW, by default, is using /wire/modules/inputfield/inputfieldCKEditor/ckeditor-4.5.10/styles.js So, I copied this into /site/templates/js/mystyles.js Next, I added the above to the 'Custom Editor JS Styles Set' field, however, it doesn't seem to load myckeditorstyles.js -- rather continues to load the one from the /wire/modules... folder. I cleared all history and caching in Safari (also tried Chrome, etc). I'm wondering if there is something else I need to do to have PW load my /site/templates/js/myckeditorstyles.js instead of the one in /wire/modules.../ckeditor-4.5.10/styles.js ? Thanks!