Jump to content

John W.

Members
  • Posts

    69
  • Joined

  • Last visited

Posts posted by John W.

  1. 44 minutes ago, kongondo said:

    Above should throw an error that you need to set output formatting of before attempting to modify the page. I am guessing you are testing with debug off. Try below. It should work.

    <?php
    
    namespace ProcessWire;
    $b->of(false);
    $b->images->add($newpreviewimage);
    $b->save();

     

    Absolutely wonderful!  Thank you so much.

    (Just a note for anyone reading this, the add() will include the photo along with the description and any image tags.)

    I'll leave the working code below.

    <?php
    // get the first image from an array of images
    // create a new preview image
    // save the new preview image to another field along with the description and keyword tags
    
    namespace ProcessWire;
    
    $businesses = $pages->find("template=business");
    foreach($businesses as $b) {
        $b->of(false);
         $imagetouse = $b->page_slides->first();
    
         $newpreviewimage = $imagetouse->size(1200,630);
    
         $b->seo_preview_image->add($newpreviewimage);
         $b->save();
    
    }
    
    ?>

     

  2. Hi,

    I'm having trouble figuring how how to do this. Basically, I have a large number of businesses that already have images. What I'm trying to do is grab the first image, resize it to make a copy, then add the copy to another image field.

     

    <?php
    
    // get the first image from an array of images
    // create a new preview image
    // save the new preview image to another field along with the description
    
    $businesses = $pages->find("template=business");
    foreach($businesses as $b) {
    
         $imagetouse = $b->page_slides->first();
    
         $newpreviewimage = $imagetouse->size(1200,630);
    
      // this is confusing me , see next comments
      
         $b->images->add($newpreviewimage);
         
      // it seems in the above line that it would be logical to add something like this instead:
      // $b->seo_preview_image->url = $b->images->add($newpreviewimage);
    
         $b->seo_preview_image->description = $imagetouse->description;
    
         $b->save();
    
    }
    
    ?>

     

  3. Hi,

    I'm on my last step before going live with a site, and I'm having an issue with redirects in PW.

    on my old processwire site, for example, I have a news article on my old site named "rabbit-workshop", just a news article about an upcoming rabbit raising class in the area.

    /news/rabbit-workshop/

    what I need to do on my new site is add an additional path:

    /news/county-name/rabbit-workshop

    I'm not sure where to add this in the PW .htaccess file.

    Also, my redirect isn't working properly. Any help would be appreciated.

    RewriteEngine On
    RewriteRule ^news/(.+)$ /news/washington-county-news/$1 [L,R=301]
     
  4. Hi, have a site where I set up a news category, then under that I have different regions where editors in those regions can add news stories.  I'm trying to figure out how to allow each editor to only add/edit stories in their region, and not allow editors from other regions to edit them.

    example:

    News  (template:news-category)

         Washington County (template:news-region)

                   My First News Story for Washington County by Editor 1 (template:news-article)

         Jefferson County (template:news-region)

                   A News Story by the jefferson county editor (template:news-article)

          Taylor County (template:news-region)

                  A news story by a Taylor county editor (template:news-article)

     

    I really don't want to create 3 different news-region templates along with 3 different news-article variations, and 3 different types of Editor roles.

    Is there a way / module that will let me say, "jane which is an editor can only add and edit to Washington County" and "bill which is an editor can only add or edit to Taylor County", etc?  Also, it would be nice to allow the "home office" editor to add/delete/modify contents created by the other editors, a "Super Editor" if you will.

     

    Thanks mucho!

    • Like 1
  5. Hi,

    I've tried a good while to come up with a solution to this, but, it's driving me nuts. Maybe someone could help?

    I have 3 categories.

    All Business

    • Dr. Adams
    • Dr. Smith
    • Mary's Flower Shop

    Primary Categories

    • Physicians
    • Gifts

    Secondary Categories

    • General Practice
    • Mental Health
    • Flowers

    Both Doctors have a page reference fields to the Primary Category->Physicians

    However, Dr. Adams has a page reference to Secondary Categories->General Practice, and Dr. Smith has a page reference to Second Categories->Mental Health

    In short, using this method I can assign multiple primary and secondary categories using Page References, to each business.

    The trouble I'm having is I'm trying to output only the Primary and Secondary categories that are in use by any businesses, without duplicating the Primary categories, like so:

    Physicians

    • General Practice
    • Mental Health

    Gifts

    • Flowers

     

    I've been using a call like this:

    $businesses = $pages->find("template=business-directory-abusiness,bus_region=$region,bus_cat_1=$maincat,bus_cat_2=$subcat")->unique();

    Where my problem lies, is this causes the below, but, I'm trying to group them as shown above.

    Physicians

    • General Practice

    Physicians

    • Mental Health

    Gifts, Flowers

     

    I've also tried running a for loop to create an array, ($maincat=>id, $subcat=>id, $maincat=>title), then run array_unique(). Still no luck.

     

     

     

     

  6. So, I have a page called NEWS with children that use a template named news_article. Currently I have NEWS set to list children, in the admin side, by published. 

    Well, I added a checkbox field called pinned_article. If checked, it just pins the article to the top when listing news on the visitor side...fine. 

    What I’m trying to do on the admin side is list in the tree all the news articles by pinned_article,published (the equivalent of a selector such as sort=-pinned_article, sort=-published)  

    All I see is a drop down for selecting a single field  Would be nice to add a text field to allow selectors for more complex sorting  

    Any work-arounds?

     

  7. Hi, for some reason I’m getting the old PW login screen, as shown. Can someone guide me in replacing it with the current PW login screen (the one that does not display the PW version? I’m guessing I could copy files from another install, which has the newer login screen, uncertain what to copy. 

     

    Thanks!

    After login, my Reno displays fine. 

    Trying to replace/update this:

    C4DD9255-E02E-4DE7-B071-5504B445D4A8.thumb.jpeg.f5e92ee8aa0c952654f1a54544c4c87c.jpeg

     

    My Reno theme displays fine and is ok. 

     

    2BE222B2-B936-4CCA-B703-DCEFA312186C.thumb.jpeg.bc6ad6c7a75fc91a64c17338a3147acc.jpeg

    AB1FEEA4-8055-42DA-AE14-AF5224768525.jpeg

  8. I think I found a quick solution:

    # cycles through all the current $page parents then
    # returns the parent that is #x in the list
    # $page is the current page, $parentNumber is the 
    # parent to find and return in the tree
    
    function getParent($page, $parentNumber) {
       $cnt=0;
    
       foreach($page->parents() as $p) {
        $cnt++;
         if($cnt == $parentNumber) {
              return $p;
          }
         }
         return false;
    }
    
     #pass the current $page and return its third parent
    
     $parentPage = getParent($page,3);
     echo $parentPage->title;

     

  9. Yeah, tried that, it pulls the first child under DEPARTMENTS

    This doesn't work when you have several departments such as

    DEPARTMENTS

         HUMAN RESOURCES

                About HR

                Job Listings

                          Job 1

                          Job 2

         ADMINISTRATION

                About Administration

        EMERGENCY OPERATIONS

                About Emergency Operations

     

    In the case above, your suggestion would always return "Human Resources"

  10. Working on a project where I have different categories of Departments, under departments I have Offices, and each office has multiple pages.

    DEPARTMENTS

         HUMAN RESOURCES

              About Human Resources
              Job Listings
                   job 1 details page
                   job 2 details page

         ADMINISTRATION

             About Administration
             Meet the Administrator

    -----------------------------

    stored in HUMAN RESOURCES is a background image and title of the department.

    Instead of creating a background image for each office page (and it's sub pages like job 1 details page), I'm using the background image stored in HUMAN RESOURCES for all the child pages.

    I'm familiar with using $page->rootParent, however, this will return DEPARTMENTS rather than the office, e.g. HUMAN RESOURCES that each sub page belongs to.

    I thought about using a recursive function to traverse from the current page, when it reaches the template "office". Basically, if I'm in job 1 details page, it would traverse back up the tree until it reaches "office" template, such as "HUMAN RESOURCES".

    Has anyone done something similar, but, using a built in method that I'm missing?

    Thanks.

     

     

     

     

  11. On 9/18/2019 at 9:48 PM, adrian said:

    So the $pages->find finds the page in the 3rd url segment and displays the content of that page? I guess I don't understand why that is better than having a template file for the document template

    I don't have a php template for documents.  The non-php template, for documents just holds a title, summary and has pdf attachments available for download.

    Therefor, when /documents/ does a query, it finds all the "document" templates and lists them with a title, summary, and links to either view or download a pdf.

    See this screenshot:

    /documents/ simply does a list like this where visitors can see a date, title, summary and download or view pdf files. the information for each entry is a php-less template with date, title, summary and a file-type pdf field for attaching the pdf.

    493784289_ScreenShot2019-09-21at10_29_38AM.thumb.png.812936e7921bb108fe4828b1e150ebdd.png

  12. Yup, that is what I'm doing. However, the trouble is I'm using a Page Reference field in another template, which creates a link like /documents/document-category/nameofdocument

    Of course, it throws a 404, since "nameofdocument" doesn't exist.

    So, what I did, for "nameofdocument", I created a php file for that template that redirects to /documents/results/document-category/.  Since /documents/results/ doesn't have a template it just treats results/ like a url segment. ?

  13. Hi,

    I've set up a structure like so:

    842507936_ScreenShot2019-09-18at11_33_36AM.png.5718819b5136c9e2f8ea66fb38c16168.png

     

    these are the templates

    documents -> documents_category -> documents_document

     

    Basically, when someone goes to /documents/ it creates a listbox of categories and the page then lists all the documents_document in that documents_category.

    In my listbox, I have the url value set to /documents/document_category

    for instance /documents/human-resources/ would list all the documents contained under human-resource.

    Herein is the problem, I just want to use the human-resources as a url parameter to pass to /documents/ rather than processwire trying to load an actual page at /documents/human-resources/documentname

    Right now, it goes to /documents/human-resources/documentname/

    Is there a way to set processwire to treat human-resources as a url parameter and not attempt to load the child page /documentname/?

     

     

    Note, I added a path like /documents/results/document-category/ which works, however, I need this to work in the back-end when using a page select field.

    The only solution I could think of was creating a documents_category.php file that takes the url, /documents/document-category/ and changes it to /documents/results/document-category/ then does a session redirect. Using this  a page select would go to /documents/document/category/ which inserts the "/results/" segment and then redirects to /documents/results/category-name

     

    Thanks!

     

     

     

  14. On 11/11/2018 at 12:33 PM, NooseLadder said:

    Hi,

    I have a site that I want to change the primary domain at the hosting level. All else remains the same. I read the above posts but I cannot find this in my config.php. It is an old version of PW 2.3.1. Am I safe just to make the domain change anyway?

    This was on old post. Actually, what I do is fresh install processwire on the server.  When I get ready to upload my project, I dump my local mySQL database, switch to the online site where I drop tables and import the database.  After that, I uncomment about 3 lines of code in my index.php file that changes the processwire admin password in the database. From there, I just login and also change the passwords for any other roles that my be set up.  Ryan pointed me to the info about setting the passwords via the PW api.

    In the past I used phpMyAdmin to dump out the database, now I use the dbbackup() module, save the backup file, then switch to processwire on the server and use dbbackup() to import the dump.

    • Like 1
  15. This is really a general question about managing processwire projects located on a remote development server and syncing changes with git.

    So, I have a project in my templates folder on my mac. I run Ubuntu on a VM that monitors the shared mac folder with grunt, as I save changes in Sublime on the mac, it kicks off grunt (grunt, npm, nodejs etc, is installed on the Ubuntu VM) to compile my SASS, etc in the templates folder on the mac. Hope I didn't lose you there.

    Now, I want to be able to edit my code on my desktop, laptop from any location. So, I figure I would set up an Ubuntu install on development server, something like Digital Ocean, install npm, nodejs, grunt, etc (just like I did with the VM).

    I guess what it comes down to, if I edit my code on my mac, it would push the save files out to Digital Ocean, where grunt is running, and grunt would kick off my SASS compiler, etc. Then if I jump onto my laptop from a remote location it would sync back a copy of my templates folder to the laptop. So, if I edit code on my mac or laptop, they will push the changes to the remote Ubuntu server where grunt runs to compile my sass or compress But, it also syncs back changes to both the laptop and mac.

    I'm not really sure if this is the best approach. If you have any input on using something like git to sync your templates folder between a server that watches and compiles changes and for instance a desktop computer and laptop, I'd really like to hear it. Please don't tell me to learn emacs, lol.

    Thanks for your time and input.

    john w.

     

  16. Look around for a while, but, no luck.

    Using the built in pagination, renderPager();

    With pagination, is there a way to append a named anchor to the renderPager() page number?

    for instance:

    instead of the default

    somesite.come/inventory/page2

    but, add an anchor...

    somesite.com/inventory/page2#myanchor

    or

    Or, would I have to put the anchor name into a segment, get the name, then use javascript to jump to the anchor?

    such as somesite.com/inventory/myanchor/page2

     

    thanks

     

  17. 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:

    5a5d2863e7406_ScreenShot2018-01-15at4_16_02PM.png.822392d3608ac64be13bc668b2540886.png


    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 :

    5a5d2a49076c6_ScreenShot2018-01-15at4_24_37PM.png.f7a586718fc487f600b6c1e1d86ccf13.png
     

    ---------------------------

    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.

    5a5d2d8ba9b40_ScreenShot2018-01-15at4_16_24PM.png.f9636d1a9224e198ca00a38f7478d3c2.png

     

    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

     

    • Like 5
×
×
  • Create New...