Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/16/2017 in all areas

  1. $selector= 'template='.$template.', limit=4, sort=random'; $subs = wire('pages')->find("$selector"); // $subs is a PageArray foreach ($subs->children as $tree_item) { // A PageArray can't have children, only a Page can have children
    3 points
  2. Hi, @Robin S Learn something new today. Thanks. Gideon
    2 points
  3. @Gideon So, there is indeed a $page->find() method: https://processwire.com/api/ref/page/find/ @xxxlogiatxxx, I've read your question a couple of times but I can't work out what you are trying to do. You populate a variable you have called $fields. Firstly, you should choose a different name for this variable because $fields is the name of an API variable: https://processwire.com/api/ref/fields/ Secondly, you populate this variable from $page->find() and the result of this will be pages not fields. Can explain more about what your aim is?
    2 points
  4. Nice catch - apparently I am a bit slow today
    2 points
  5. Can you please be a little more descriptive of what problems you are having, so someone can adequately help you (i.e. what errors are you getting)? Thanks
    2 points
  6. @adrian, Updated and workin' great! Thanks for your efforts! ps. We need a Buy-A-Beer button in this forum!
    2 points
  7. This is just through a windows utility accessing A WD mycloud drive. But I am ignoring it and doing other stuff
    1 point
  8. You might want to do some recursive CLI "magic" in order to get rid of them. 10 hours? I would never wait for it, it is better to do it at a lower level
    1 point
  9. Merhaba @Cengiz Deniz, The problem is you're trying to iterate over children of some PageArray ($pages->find() returns PageArray), but only Page objects can have children like @Robin S pointed out. You should directly iterate over them like foreach($subs as $tree_item){} and you should be ok. Another problem would be that you're surrounding your selector inside double quotes. <?php $selector= 'template='.$template.', limit=4, sort=random'; $subs = wire('pages')->find("$selector"); // your selector would become "'template=...'" // you should $subs = wire('pages')->find($selector); // or just use double quotes for variable interpolation to strings $subs = wire()->pages->find("template=$template, limit=4, sort=random"); Now, I'll show you a different, but better (IMHO) way to tackle this. Instead of using a function, I prefer refactoring this to its own partial template whose only purpose is to render given category. And instead of manually counting columns, I prefer using array_chunk(). <?php namespace ProcessWire; // inside /site/templates/home.php // (or whereever you're building your categories) $category = $pages->get($catPageId); $categoryItems = $pages->find("template=$template, limit=4, sort=random"); $rendered = wireRenderFile('partials/category', [ 'category' => $category, 'categoryItems' => categoryItems, 'colCount' => 4 // or whatever ]); // then echo your rendered output anywhere echo $rendered; // Inside /site/templates/partials/category.php $colCount = $colCount ?? 2; // if not provided, default col count is 2 // divide posts into arrays of $colCount items. // you need standard PHP arrays, which you can get using getArray() method $chunked = array_chunk($categoryItems->getArray(), $colCount); ?> <style> /* separate your styles from markup, and even better, into its own CSS file */ .item { margin-bottom: 10px; padding-top: 10px; padding-bottom: 10px; } </style> <div class="category"> <!-- Render anything about category here --> <h2><a href="<?= $category->url ?>"><?= $category->title ?></a></h2> <!-- Then rows --> <?php foreach($chunked as $row):?> <div class="row"> <!-- Then items inside rows --> <?php foreach($row as $item): ?> <div class="item col-sm-<?= $colCount ?>"> <h3 class="item__title"> <a href="<?= $item->url ?>"><?= $item->title ?></a> </h3> <p class="item__summary"><?= $item->summary ?></p> </div> <?php endforeach ?> <div class="row"><!-- remember to close your rows --> <?php endforeach ?> </div> Hope this was helpful. Ask away if you have further questions.
    1 point
  10. How do you know the $subs query is working? Install TracyDebugger and do a: bd($subs->each("title")); and see what pages are being returned. If none, then bd($selector); to see what the actual contents of the selector are - mostly it would be good to know what $template is actually returning.
    1 point
  11. I added screenshot. $subs query and category title are working well. But then query results do not appears. Thank you very much for you support.
    1 point
  12. If you have control over the server and you're able to install PECL module (pecl_http) on PHP, then http_send_file() function is the most straightforward way to implement partial downloads. Otherwise you have to implement it manually using a code similar to one in SO link above. http://php.net/manual/fa/function.http-send-file.php
    1 point
  13. Thanks @rick - I have pushed an update that fixes this. I also decided to show all the argument settings in the Selector Queries section, so it now looks like this:
    1 point
  14. https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#compiled-template-files "It can be disabled globally by setting $config->templateCompile = false; in your /site/config.php file. If you do disable it, you'll likely want to add a namespace ProcessWire; to the top of your PHP template files where necessary." In practice, the simplest solution is to always add <?php namespace ProcessWire; if none other is required.
    1 point
  15. It looks like you need to set some headers to enable byte range requests and check incoming requests for byte ranges that client is currently at. Check out this SO answer: http://stackoverflow.com/a/157447
    1 point
  16. Here's how you might dynamically create it with ProcessWire without tinkering with .htaccess files. Create a new template, call it robots, and set its URLs > Should page URLs end with a slash setting to no, and Files > Content-Type to text/plain. You should tick disable Append file and Prepend file options as well. Optionally set its Family > May this page have children to no, and Family > Can this template be used for new pages to one. Family > Optionally Set allowed templates for parents to home only. Create a new page under homepage, set its template to robots, and name as robots.txt. Create a new template file at /site/templates/robots.php, inside it you type <?php namespace Processwire; // render different robots.txt depending on your own conditions. if ($config->debug) { // use PHP_EOL to create multiline strings echo <<<PHP_EOL User-agent: * Disallow: / PHP_EOL; } else { echo <<<PHP_EOL User-agent: * Disallow: PHP_EOL; } and done. You should be able to see robots.txt at the url /robots.txt.
    1 point
  17. Sounds like you have a good handle on how the process will work, so no reason to worry I think. I've just done something very similar so I can attest that it's quite simple to do in PW. Regarding 1 & 2: most likely you will be querying an API endpoint that will return a JSON string to you. You'll probably find the WireHTTP class useful here - that's what I used. The getJSON() method will convert the JSON response into an associative array that contains all the data you requested. Tracy Debugger will be useful for exploring this array. Then you will use some part of the data as a unique identifier (you could use the title string but there's probably some kind of reference code that will be a better candidate) and based on whether you can find an existing page with that identifier you will either create a new page or update an existing page. Then it's simply a matter of matching items in the array to fields on your page and saving the page at the end. You can use a lazy cron function to automatically query the API endpoint every 24 hours. To delete pages that are no longer contained in the JSON response you can collect all of the unique identifiers in the response and then use a PW selector to get pages not matching any of those identifiers. Those pages you delete.
    1 point
  18. For a project I've posted yesterday I built a basic module to subscribe users to a Sendy installation. I love Sendy and my client too as we use it to send lots of emails using Amazon SES costing almost nothing at all. Do guys think that's worth to post about? It's very basic now, it doesn't use Sendy's API at all, it just send the data using POST to subscribe the users to different lists.
    1 point
×
×
  • Create New...