Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

6 Neutral

About Leftfield

  • Rank
    Jr. Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Here is final solution for the link: /samsung-s10-mobile-phone/pr/f980fd84/ I got tree like this: Products/product articles/details NOTE: template articles has name/URL: "pr" NOTE 2: Product is the main name of the article/articles but all other fields are going in the template details. It was made in case of duplicate name so the hash would be The only difference but the product page would keep children with hash name. See the URLs and picture bellow /samsung-s10-mobile-phone/pr/f980fd84/ /samsung-s10-mobile-phone/pr/d8h3jk1n/ NOTE 3: I am using hidden hash_field as text field on the template details for recording hash URL segmentation enabled on all templates. In product template there is: Profields: Page Table (with the same name as template "Details") with action on product page. Module for making hash: <?php namespace ProcessWire; class AddHashField extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Hash Field', 'summary' => 'Populate hash field of product template', 'href' => '', 'version' => 001, 'permanent' => false, 'autoload' => true, 'singular' => true, ); } public function init() { $this->pages->addHookBefore('saveReady', $this, 'AddHashField'); } public function AddHashField($event) { $page = $event->arguments[0]; if($page->template != 'details') return; if(!$page->title){ $hash = hash('CRC32', microtime()); $page->set('title', $hash); $page->set('name', $hash); $page->set('hash_field', $hash); $this->message("Hash is set " . $page->hash_field); } } } In my (probably yours home.php) _main.php file, on the top: <?php namespace ProcessWire; if ($input->urlSegment1 && $input->urlSegment2 == 'pr' && $input->urlSegment3) : $pagename = $input->urlSegment1; $hash = $input->urlSegment3; $match = $page->find("template=details, name={$hash}"); include('views/' . $match->template . 'details.php'); return $this->halt(); endif; On details template: <?php namespace ProcessWire; $parent_name = $input->urlSegment1; $name = $input->urlSegment3; $parent_page = $page->findOne("template=product, name={$parent_name}"); $page = $page->findOne("template=details, name={$name}"); include("./head.inc"); include('./nav.php'); ?> <h1><?= $parent_page->title ?></h1> Function detailsUrl in function.php: function detailsUrl($item){ $out = ''; foreach($item->details as $c){ $out .= '<a href="' .$item->name .'/'. $item->parent->name .'/'. $c->name . '">' . $c->headline . '</a>'; } $out.= '<br />'; return $out; } Listing on the home template: <?php $pages = $pages->find("template=product, sort=date, limit=10"); foreach($pages as $item) : echo detailsUrl($item); endforeach; ?> Now, this is not finished code in home.php, it doesn't list on all products... But I leave your imagination how to handle further. IF anyone needs this rare solution I am here to help. Thanks to motherf.... @OLSA (we are friends) who doesn't let me give him cup.
  2. One of the easiest solutions in my head is: to exclude "/" from regex when creating page->name. Or to query page->title after save, remove number and copy database page_paths path to pages name after save. Hash is unique and that's what makes the page unique.
  3. Hi @All 🙂 I made custom URLs I have unique hash at the end of the every URL of template=product: /nike-air-max-man-running-trainers/pr/832a2805/ Now, I don't need PW to check is there a duplicate page name because it will add to URLs numbers like this (-1, -2, -3...): /nike-air-max-man-running-trainers/pr/832a2805/ /nike-air-max-man-running-trainers-1/pr/9876j536/ /nike-air-max-man-running-trainers-2/pr/54b5221/ /nike-air-max-man-running-trainers-3/pr/0o542761/ etc. How to stop PW from doing this?
  4. OK. Here it is. ProcessWire 3.0.123 PHP 7.2.18 1. In "product" template turned on "Allow URL segments". 2. Made text field: "hash_field" and added it to product.php template. Set visibility to: Open when populated + closed when blanked + Locked (not editable) In site/ready.php <?php namespace ProcessWire; //* conf segments of URL of template product *// wire()->addHook("Page(template=product)::path", function($e) { $page = $e->object; $e->return = "/{$page->name}/pr/{$page->hash_field}/"; }); Made a module "AddHashField" with simple hash CRC32 to populate "hash_field" so the URL will be as short as possible. <?php namespace ProcessWire; class AddHashField extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Hash Field', 'summary' => 'Populate hash field of product template', 'href' => '', 'version' => 001, 'permanent' => false, 'autoload' => true, 'singular' => true, ); } public function init() { $this->pages->addHookBefore('saveReady', $this, 'AddHashField'); } public function AddHashField($event) { $page = $event->arguments[0]; if($page->template != 'product') return; if(!$page->hash_field){ date_default_timezone_set('Europe/Podgorica'); $new_date = new \DateTime(date('Y/m/d 00:00')); $formated_date = $new_date->format(YmdHi); $hash = hash('CRC32', $formated_date); $page->set('hash_field', $hash); $this->message("Hesh is set " . $page->hash_field); } } } Now, I am using 'views/' folder for templating so, instead of using home.php I am placing this on the top of the _main.php file. <?php namespace ProcessWire; if ($input->urlSegment1 && $input->urlSegment2 == 'pr' && $input->urlSegment3) : $pagename = $input->urlSegment1; $hash = $input->urlSegment3; $match = $page->findOne("template=product, name={$pagename}, hash_field={$hash}"); if (!$match->id || !$match->hash_field) throw new Wire404Exception(); include("./head.inc"); include('./nav.php'); include('views/' . $match->template->name . '.php'); include("./foot.inc"); // echo $match->render(); // problem with looping page endlessly + fatal error return $this->halt(); endif; NOTE: echo $match->render is causing massive looping until Fatal Error. I don't have idea what is causing that. Tried to turn off xdebug etc. Special THANKS to @Zeka
  5. OK. I think I am resolving this. Will post everything
  6. I placed the URL segmentation code in _main.php. While natural PW URL is still working, I am getting error: Fatal error: Uncaught Error: Maximum function nesting level of '50' reached, aborting! I have turned off xdebug, tried with ini_set('xdebug.max_nesting_level', 10000); in config.php but it loads forever.
  7. @Zeka First part of the code I placed in ready.php file. The second part is in template product.php URL segmentation is enabled in backend. When saving article, I got message with desired URL. But still get 404. I am using latest PW and WAMP. $input->urlSegment1 is empty (var_dump): (length=0)
  8. @Zeka Thank You! I will try and give feedback what I have done. I need the URL to be recorded in the database on Page Save, not alternated on the fly. @wbmnfktr I am making website similar to yellow pages and I need SEO. Main reason - hash will be kind of ID of the page. I am not alternating real ID because of pagination (I am OK with PW but not that good)
  9. Thank you @psy, I think don't need that. To explain my problem a little bit better: 1rst: I need to build URL before page save and add hash after forward slash. IT doesn't matter is it JS or PHP: $new_name = $page->title . '/' . $hash; The problem is: The core is converting forward slash "/" to "-". Probably something with $sanitizer->pageName but I am stuck here. 2nd problem is to move parent name after the child's name or to remove it completely - probably easiest way "Name format for children".
  10. Hi @All 🙂 I have template product in category products And have URLs like this: example.com/pr/salomon-gtx-3d-1930649707/ The last numbers, the hash, is added by a module before save page. What I need is this: example.com/salomon-gtx-3d/pr/1930649707 Is there a way to do this on the fly in the backend and record URL to database? A hint please
  11. Hi @All, @Wanze thanks for the module! Please mates, is there a way to add pdf button/link to backend template? I need to print particular template from backend.
  12. Managed to install. It is not working in ANY editor. Neither youtube, nore twitter, nor facebook, nothing. I can write exact same non-working module for like 1 sec and less. Please, someone delete this module.
  13. Hi for New Zealand! Thanks for helping Rob! Finally solved in this simple way (this PW has a zillion options 😍) $properties = $pages->find("template=property, sort=pstatus, sort=date");
  • Create New...