Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/15/2016 in all areas

  1. Every thing is a page! Om! Every page has a ID! Om! $articleCountPerAuthor[$author->id] = $articleCount; Should be save!
    4 points
  2. I would do something like you mentioned: $articleCountPerAuthor = array(); foreach($pages->find("template=author") as $author){ $articleCount = $pages->count("template=article, author=$author"); $articleCountPerAuthor[$author->title] = $articleCount; } arsort($articleCountPerAuthor); // result of $articleCountPerAuthor /* array( "Actor XXX" => 500, "Actor XXX" => 400, "Actor XXX" => 200, )*/ $pages->count() - little overhead, since it doesn't load the pages like $pages->find() does arsort() - Sort an array in reverse by array value Since Processwire is extremly performant and efficient in handling pages you shouldn't have Problems.
    4 points
  3. @mr-fan has made a module that does this: AutoImagePages
    4 points
  4. In v044 I replaced the field edit link appearance to tooltips. In some cases the field names were overlapped by other items but in tooltip this doesn't occur. There's also a tooltip for edit page template when hovering on the page title. In fact, the FieldEditLinks tweak was renamedt to FieldAndTemplateEditLinks as they share the same settings. The template edit feature is available for the default theme too.
    3 points
  5. There isn't one, other than passing the instance into the function as parameter. But really a class is way better in handling this kind of state. <?php namespace ProcessWire; class Helpers extends Wire{ public function getGlobalSeo() { return $this->wire('pages')->get('/')->seo; } } In the init.php $helpers = $this->wire(new Helpers); // Wire the instance into the helpers class $this->wire('helpers', $helpers); // Add as api variable In your templates $seo = $helpers->getGlobalSeo(); …
    3 points
  6. It's because all other options are aware of their instance (e.g. a page of instance1 will get the configs of instance1), whereas the global wire function does not have state and therefore does only ever return the "primary" instance, which is simply the first one ever instantiated. Edit: Maybe 'avoid' it to hard, but one needs to be aware that the function is not aware of additional instances. Especially in hooks or alike, where people are currently often using wire() one should rather use $event->wire() so the hook is not prone to using a different instance than intended.
    3 points
  7. So /site/ should be renamed to /enjoy/
    3 points
  8. There are basically four different environments to talk about. TemplateFile TemplateFile is core class, which does include your template files, but does also power things like $page->render(), wireRenderFile(), wireIncludeFile() and others. This class will automatically make all API Variables available as local variables. Meaning all those included files can directly use $pages, $page, … . It won't work inside any functions defined in those files, because of the way PHP does scope variables. Classes extending Wire Every class, which is extending the Wire class will have access to API variables via $this->pages, $this->page, if the properties or __get() are not overwritten. Also there's $this->wire('pages'), which is less likely to be overwritten (even some core classes need to use $this->wire()). Anonymous functions There are some methods in the processwire code, which accept anonymous functions as parameters (e.g. WireCache). Those anonymous functions can retrieve api variables as parameters, even though I'm not sure how exactly this is working or if that's often used. Everywhere else Outside of wire classes, template files and special anonymous functions there's the wire() function, which is basically the same as $this->wire() in wire classes, but as a global function, which is accessable anywhere after pw is started. With PW 3.0 and multi-instance this is the option to avoid. Places, which technically are number 2, but it may not be apparent to everybody: Custom PHP code for fields like FieldtypePage or FieldtypeMarkup: As those PHP code is evaluated/run inside those (input)field classes there's (besides manually available local api variables) always the option to use $this->pages or $this->wire('pages'). All those template files included by the TemplateFile class: For the same reason as above there's not only $pages available in those template files, but also $this->pages, $this->wire('pages').
    3 points
  9. Yes. In the example... $authors->sort("articleCount"); ... $authors is the PageArray (WireArray) and "articleCount" is the property we sort on.
    2 points
  10. Another option is to set the article count as a property of the author Page object. $authors = $pages->find("template=author"); foreach($authors as $author){ $author->articleCount = $pages->count("template=article, author=$author"); } $authors->sort("articleCount");
    2 points
  11. LOL, how could I miss that!
    2 points
  12. It's definitely one possible way to go, sure. the url names are received from the db or you define them in the template? If the first is the case make sure to sanitize them e.g. $sanitizer->pageName($url)
    2 points
  13. @Mike Rockett - You are right, being able to read is an advantage.
    2 points
  14. Getting the authors with the most articles would be simple if the article pages were added to author pages rather than the other way around, but of course that's not so good for workflow. But there have been some posts on the forum that suggest linking two Page fields, where changing one updates the other. Gist by @Martijn Geerts, discussed here Gist by @Soma, discussed here and here These may also be relevant:
    2 points
  15. conventions sure..but we're talking about coolness
    2 points
  16. I think typically a sitemap does not include paginated pages. You can include a "view all" page if you have one, or the first page of results (make use of rel="next" and rel="prev" in your pagination links). Google says:
    2 points
  17. @all: Was kind of out of business for a while. Will come back and check everything in September! Also some new ideas for this module ;-)
    2 points
  18. Hi! I've been making my first modules and I've created three so far to help me learn. I would love so feedback or pull requests for improvements as I hope to write a tutorial about my work soon. In particular the third modules isn't very finished. git: https://github.com/benbyford/PW-starter-modules/ HelloUserYouSaved - adds message {your user name, page saved} in admin when a page is saved. This module shows how to implement a basic module, get and use variables, create a message in the admin RedirectAdminPages - redirect specific user role to a custom page set in the module config. This module shows how to implement module configuration, using variables saved in the admin, redirecting a user using session->redirect() HotSwapUser - Swap user on the fly in the admin or frontend of your site This module shows how users can be used in a module how to set a user permission how to install / uninstall something within your module how to create a function that can be output in the frontend of your site.
    1 point
  19. Just for reference, here is the origins of that module:
    1 point
  20. @hansv Thanks for feedback about the reason! I'm happy you solved the problem It just use the power of Processwire API and hooks
    1 point
  21. On mobile screen size AOS is simply not active, so you can see the original theme, at least for the CSS tweaks.
    1 point
  22. Good point, Can. Everything in immo.php would be communicating with the db, more specifically with the real estate tables.
    1 point
  23. I was about to report/ask for these. You saved me some typing Thanks a lot!
    1 point
  24. Oh, missed that ^^. I have updated the post. Thanks @szabesz. It's still possible to have duplicate keys(authors which has the same name?) but probably is less likely. You could add a random prefix or something which you can remove at output with str_replace() or exlode() or something...
    1 point
  25. What if we have the same number of articles? It will overwrite the previous one, won't it?
    1 point
  26. I've made a quick toggle button that enables/disables the CSS (unreleased), but that's not really helpful because all the php and js stuff are in effect. Do you think a full module enable/disable button is needed? Otoh this toggle wouldn't help you much with the disappearing search field, that comes from the Reno theme as I see. I have made a little tweak that fixes the issues you mentioned with the search field from about page width above 960px (it's available if you update the module).
    1 point
  27. The PW oekosystem never ceases to amaze me. Thx!
    1 point
  28. @biber - If you read my post again, you'll see that I mentioned that you need to place that line underneath the existing RewriteEngine on directive, not as the last rule. Nonetheless, what you have done is correct enough. Glad it works.
    1 point
  29. thanks @Can for the wirecache example. That will come handy. I am thinking of running the sql query directly to get results. This seems quite efficient. And, I will also cache the results of this. This is my query: SELECT count(pages_id), data as author FROM field_authors GROUP BY data ORDER BY count(pages_id) DESC LIMIT 10;
    1 point
  30. One thing I notice -- you should reverse the order of your rules. You have the generic ones before the specific ones. so a request to /solutions/eventdirect/eventdirect-advisory-board/ will never be resolved, because the more generic condition /solutions/eventdirect/ will always be reached first, so "eventdirect-advisory-board" will not be reached at the new location. cheers, Tom
    1 point
  31. Finally! http://processwire.com/blog/posts/multi-instance-pw3/ Working just as described for me =) (site note: I've both installs running on 3.0.30)
    1 point
  32. Basically go to http://modules.pw/, tick some boxes, put in your code and change the things up, which should be configurable. But this code is not too great to begin with as it'll require anyone using it to store the cpanel password unencrypted in the database or the file itself. ProcessHostingInfo.zip
    1 point
  33. In /site/init.php... $config->css_files = new \ProcessWire\FilenameArray(); $config->js_files = new \ProcessWire\FilenameArray(); In your Hanna Code PHP... $config->css_files->add('/site/templates/path/to/file.css'); $config->js_files->add('/site/templates/path/to/file.js'); Wherever you output your <head>... foreach($config->css_files as $css_file) { echo "<link rel='stylesheet' href='$css_file'>"; } foreach($config->js_files as $js_file) { echo "<script src='$js_file'></script>"; } See the code for the FilenameArray methods available: prepend(), remove(), removeAll(), etc. P.S. you can use the existing core $config->styles and $config->scripts FilenameArrays but other files might be added to these by certain modules so cleaner to create your own FilenameArrays I think.
    1 point
  34. I believe you can click on the red link to get the latest update (commit) for that version
    1 point
  35. Thought I'd mention this here too. Both VersionControl.module and ProcessVersionControl.module have been updated to version 1.1.0: VersionControl 1.1.0 includes new public method getHistory($page) for fetching the full history of a specific page as an array (supports pagination and filters, arguments can be checked from the code). The primary goal here was to separate the core logic of the module from display stuff. ProcessVersionControl 1.1.0 greatly improves the diff output for Page fields. Instead of IDs and string diff it will now use actual labels and custom diff logic. This not only looks better, but also makes more sense than comparing a list of numbers and displaying the smallest possible change set between them The Page field update was thanks to this pull request, though it ended up being a bit more complicated than that: https://github.com/teppokoivula/VersionControl/pull/2.
    1 point
  36. Could you reveal more details about your templates? (Their fields, etc.) And what is the structure of the CSV file? (First line of column titles, and a sample of the following lines) Edit: Wasn't that intended to be $author = $pages->find("
    1 point
  37. Thanks for the hint, it's fixed. I thought I tested the link! Considering this module and future development of PW. Yeah, I was playing around with that yesterday, but couldn't see a solution. Unfortunately I knew this would one day lead to complications. :/ After little experimenting I think we need to rethink $page->url rewrites Multisite does in the admin and consequently in the front-end. I always feared it was maybe dangerous/adventurous and would lead to problems sooner or later. There's so many things to consider it's crazy. So, after long thinking and testing, I'm heading towards letting the $page->url alone, to not get in the way as much as possible. Then we just have to make sure 2 things: 1. when an url is viewed containing a "domain" in its path that is recognized, to redirect the correct domain/url. So a view link will just work. 2. to have correct url on the front-end output, we can parse the $page->render() output and replace/fix those urls output from templates and RTE's. This way such new features like the "View" options work out of the box. Also cross Domain linking in RTE would work also. I got a test version working so far but not sure about what to further consider with this new approach.
    1 point
  38. WillyC's example just modifies the output of the $page->path() function (which is also used by $page->url). His intention there is to change what URL gets sent out when you call $page->url. It's really no different than making your own function and using it instead, except by using a hook like this, you can continue to use ProcessWire's API and get the result out of it that you want. Ultimately it's just a syntax convenience. While his hook example handles the URLs that get output in your markup, you still have to have something to look for and capture those URLs. Perhaps you could use mod rewrite, but typically you would use the "URL segments" feature that you see on the "URLs" tab when editing any template in PW admin. Lets use a simple example of your homepage template (home) with filename home.php. And lets say you want to make it so that when someone access domain.com/contact/ (a URL that doesn't currently exist) you want it to display the page that lives at domain.com/about/contact/. So you are setting up your site to respond to the shorter URL of /contact/ (rather than /about/contact/, where the page actually lives). Go to Setup > Templates > home > URLs. Click the checkbox to "allow URL segments", and save. Now edit your /site/templates/home.php file, and do something like this at the top: if($input->urlSegment1 == 'contact') { // render the /about/contact/ page echo $pages->get('/about/contact/')->render(); return; } else if($input->urlSegment1) { // throw a 404 throw new Wire404Exception(); } // otherwise continue normally and display your homepage.
    1 point
×
×
  • Create New...