Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/13/2013 in all areas

  1. Hi all, I've just pushed a new fully responsive site profile to Github: Unsemantic Site Profile for Processwire 2.3 After having tried seven zillion responsive grid systems, boilerplates, frameworks etc. I finally opted for Unsemantic Grid System. Mainly because it supports IE7, is lightweight and includes Compass/SASS. I've designed the profile as a starting point for development according to my needs. This includes almost no styling, an easy-to-use solution for placeholder images and three teaser boxes on the front page. In addition, I converted the .sass files that come with Unsemantic to .scss because I like the syntax better. Glad if you give it a try and find it an improvement for your workflow. You can see a preview here. Download from Github: https://github.com/christophlieck/UnsemanticSiteProfile
    7 points
  2. virgintribesa.com Created for Virgin South Africa Employee engagement - they're yet to have much content up there but the site is pretty much finished.
    5 points
  3. I don't think categories is the way to go here. 1. Nested Structure This is a good example where the date structure could be used to create the articles. Then you would a) have the urls already and b) an easy way to create lists and such. Additionally add a date field to the article template so you can choose the date and use that for additional searching. /dagboek/ /2008/ /januari/ // or use "01" as name whatever you like /article14012008/ /article15012008/ /februari/ /article01022008/ /2009/ /januari/ Then loop the years and months in a simple nested php script using API. You don't need to check if there's a year or month with articles if you create months manually. $years = $pages->get("dageboek")->children(); $out = ''; foreach($years as $year) { $out .= "<ul>"; $out .= "<li><a href='$year->url'>$year->title</a>"; if($year->numChildren) { $out .= "<ul>"; foreach($year->children() as $month) { $out .= "<li><a href='$month->url'>$month->title</a></li>"; } $out .= "</ul>"; } $out .= "</li>"; $out .= "</ul>"; } echo $out; Then on the years or months template file, you simply render out their children in any fashion you like and may add pagination using the built in Pager module. You'll have urls like /dagboek/2008/01/page1, dagboek/2008/01/page2 2. Flat The other route would be to use a flat structure and add articles to the /dagboek/ parent. Then add a date field to the article template you can define the day this article is for. Then use a script that checks for articles (oldest, newest) and generate a menu with virtual urls for each year and month that has articles. The URL then can be resolved using urlSegments to show a list of articles for the selected month. You'd have to enable url segments on the dagboek template to make this work. This is a script I created for generating a year month nested menu only for the ones that articles are found. $datefield = "mydate"; $template = "article"; $url = $pages->get("/dagboek/")->url; $newest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=-$datefield, limit=1")->first->getUnformatted($datefield)); $oldest = (int) date("Y",$pages->find("template=$template, $datefield>0, sort=$datefield, limit=1")->first->getUnformatted($datefield)); $out = ''; for($y = $oldest; $y <= $newest; $y++){ $out .= "<li>"; $out .= "<a href='#'>$y</a>"; $month_out = ''; for($m = 1; $m <= 12; $m++){ $month_start = strtotime("$y-$m-1"); $month_end = strtotime("$y-$m-1 +1 month"); $selector = "template=$template, $datefield>=$month_start, $datefield<$month_end"; if($pages->count($selector)) { // use count instead of find for fast query $month_out .= "<li><a href='{$url}$y/$m/1'>$m</a></li>"; } } if(strlen($month_out)) $out .= "<ul>$month_out</ul>"; $out .= "</li>"; } echo "<ul class='menu'>$out</ul>"; Then, on the dagboek template something like: if($input->urlSegment1 && $input->urlSegment2) { $year = (int) $input->urlSegment1; // 2008 $month = (int) $input->urlSegment2; // 02 $start = strtotime("$year-$month-01"); $end = strtotime("$year-$month-01 +1 month"); // find the articles for within that current month $articles = $pages->get("/dagboek/")->find("template=article, date>=$start, date<$end, sort=-date"); foreach($articles as $article) { echo "<h2>$article->title</h2>"; echo $article->body; } } Just rough examples.
    5 points
  4. @Nik Thanks so much for that, the code is working perfectly and it all makes perfect sense now! So amazingly easy! I will use the same method on other sorting issues i have that would not work out of the box with PW's $pages->find() method. I still have one problem though: I already have a lot of products in the site, and since the module hooks on the "Save" event, the field won't populate unless i go to each page and save it. There are a LOT of pages . What would be a smart method of going about this? Can i trigger the Save event on all pages that have the product template, or can i change to hook somehow? @horst Thanks for the pointers, i've taken your advice and have begun reading up on hooks and the API documentation in general, but snippets of code like Nik's one above really make a world of difference in shining some light on the whole thing. EDIT: Eureka! I managed it myself: <?php $allProducts = $pages->find("template=product"); foreach ($allProducts as $p) { $p->setOutputFormatting(false); $p->save(); echo "page ".$p->url." saved!"; } ?> Done and done. Now all the product pages have the 'first_version_price' field populated! Thanks for all the help everyone, you rock!
    4 points
  5. In PW 2.3 all jQuery traversing methods are available. So not yet in the cheatsheet is things like prevAll(selector) or nextAll(selector), nextUntil(selector) ... For what you ask I think this is what you need: $found = $page->siblings("template=mytemplate,body*=your text")->first(); if($found->id) { echo $found->body; } Nothing to explain really, except that sibling() is like find() and returns an PageArray of pages even if only one found. So to get the first from the array you add ->first. This will return on the one page and you can make sure it has one found with if($found->id){... Edit: ok maybe another one on a sidenote, when working with $page->siblings(), it will also return all including the page you're calling this from. So you could add a selector "id!=$page->id" to exclude it.
    3 points
  6. Starting in on a new site tonight and realized I never posted the last site we finished in March. www.la2050.org This was a information frontend site for a campaign to get people submitting proposals for a community funding project. Client was able to edit a ton of the site and never had any issues dealing with the backend. I learned a ton about markup/template organization from the threads here which were unbelievably helpful. Thanks everyone! Thanks Ryan!!!
    2 points
  7. Just wanted to let you all know, I updated the module to 1.1.9 , with another new hook method to manipulate or add your very special case classes that will get added to list_tpl's "%s". To use this, here a little example to make it clearer. I want to add a class to my page with id 1001. Ok here we go. $nav = $modules->get("MarkupSimpleNavigation"); function hookGetListClass(HookEvent $event){ $child = $event->arguments('page'); // current rendered page item (in naviation) $class = $event->arguments('class'); // the class string, may be empty or filled if($child->id == 1001){ // add your checks, use API or whatever... daytime... $event->return .= " yourclass"; // add your class names } } $nav->addHookAfter('getListClass', null, 'hookGetListClass'); echo $nav->render(); Added this to readme
    2 points
  8. Greetings, Well, thanks to this discussion, I think my decision-making is moving along! I am liking Kube's approach more and more. I plan to use it on my next ProcessWire project. Another view, and I would be very interested in everyone's opinion... I still like to create and use my own CSS structures. It's interesting to me how development/design has changed in the time I have been doing it. Not long ago (or so it seems to me), the attitude was, "Learn to do it yourself." Today, we have a legitimate attitude of, "Use pre-made code or structures." I understand and see the benefits to this, but I think we should use frameworks like Kube and Foundation, but make sure to also stay fully informed about what all those elements are doing. Otherwise, we run the risk of becoming overly reliant on a few sources for our needs, and perhaps creativity is harmed. I'm not 100% sure about all this -- and I am going to dive into Kube -- but these thoughts keep going through my mind. Again, I wonder what other people here think. On a related front, I came across this odd link today: http://www.starbucks.com/static/reference/styleguide/ Thanks, Matthew
    2 points
  9. looks like a convincing offer: i'll get everything out of one hand, from business consultancy to tax service and tree surgery. one-stop-shopping at it's best. if i only would understand the difference between webdesign and internet home pages. anyway, i'll start with a non-designed homepage and add webdesign later ...
    2 points
  10. Ha! Brilliant! I knew I was missing something simple Works like a charm. Now to go in and throw those latest posts back in my page template. Thank you muchly
    2 points
  11. Great! Wanze beat me to it....again... . The following line renders posts... $content = $page->body . renderPosts("limit={$page->quantity}");
    2 points
  12. Hi einsteinsboi, You can move the blog stuff under its own parent, let's say 'blog' and build a the normal website structure around. Like in this example: In your homepage template, you can include /site/templates/blog.inc. In this file, you find the functions to render the posts, latest comments etc. For example, render the latest 4 comments: $comments = findRecentComments(4); echo renderComments($comments);
    2 points
  13. Just added a pull request. Moved the breadcrumb to the top and adjusted the padding.
    2 points
  14. @PWired. Thanks. I am humbled. I try to do my bit. Though, truth of the matter is that I've taken much more than I've given back. There's some great people in this community; I am awed by their generosity.
    2 points
  15. Hi guys, I've been doing events sections for a few sites and for each I needed to make an iCal feed. I've wrapped up this functionality into a module now to make it a little easier for myself and anyone else that needs to make these feeds. The module is basically a simple wrapper around the iCalcreator library (a copy is included). It's modelled on the MarkupRSS module from Ryan, so anyone familiar with that should have a feed up and running in no time. Usage The module takes a PageArray and creates the feed from that. The [tt]->render[/tt] method will send the output to the browser with a generated filename and will automatically download. Because it will return HTTP headers, it has to be included before any html and is best in its own template or followed up by [tt]exit;[/tt] <?php $today = time(); $items = $pages->find("template=event, sort=start_date, start_date>$today"); $ics = $modules->get("MarkupiCalendar"); $ics->title = "Upcoming Events"; $ics->description = "Some upcoming events"; $ics->itemStartDateField = 'start_date'; $ics->itemEndDateField = 'end_date'; $ics->itemLocationField = 'location'; $ics->render($items); You can use the [tt]->renderFeed[/tt] method to return the output as a string instead, which is particularly useful if you want to debug or write the output to a file. <?php $today = time(); $items = $pages->find("template=event, sort=start_date, start_date>$today"); $ics = $modules->get("MarkupiCalendar"); $ics->title = "Upcoming Events"; $ics->description = "Some upcoming events"; $ics->itemStartDateField = 'start_date'; $ics->itemEndDateField = 'end_date'; $ics->itemLocationField = 'location'; $cal = $ics->renderFeed($items); echo $cal; I often put RSS and iCal feeds at the top of my listing pages so as not to clutter up the site tree with extra templates. This way /events/ may point to my events page, and /events/ical will point to it's feed. Here is an example: <?php // iCal feed if ($input->urlSegment1 == "ical") { $today = time(); $items = $page->children("sort=start_date, start_date>$today"); $ics = $modules->get("MarkupiCalendar"); $ics->title = "Upcoming Events"; $ics->description = "Upcoming events for my company"; $ics->itemStartDateField = 'start_date'; $ics->itemEndDateField = 'end_date'; $ics->itemLocationField = 'location'; $ics->url = $page->httpUrl; $ics->render($items); exit; } // Render the template as normal. include("./includes/head.inc"); Download and feedback You can download or fork the module here: https://github.com/f...MarkupiCalendar At the moment it only supports all day events (as these are all I have dealt with) but I hope to add time based events soon. Any feedback is warmly appreciated and feel free to report bugs or suggestions for improvement. Stephen
    1 point
  16. Module is no longer maintained. Github Repo deleted! Hello community, based on the freely available flash mp3 player (http://flash-mp3-player.net) I set a module, which creates a field to store mp3-audio files in the backend and an audio player in the frontend. mp3 files can be added by drag and drop. The audio player is configurable in module settings. (Size, colors, display of buttons, volume control, etc.) About third party Code More information http://flash-mp3-player.net/players/ Code https://github.com/neolao/mp3-player License http://creativecommons.org/licenses/by-sa/3.0/deed.en Author The Initial Developer of the Original Code is neolao (neolao@gmail.com). How to install download the 2 Files: http://flash-mp3-player.net/players/maxi/download/ http://flash-mp3-player.net/medias/player_mp3_maxi.swf http://flash-mp3-player.net/players/multi/download/ http://flash-mp3-player.net/medias/player_mp3_multi.swf Download from github the module, unzip, copy module and the 2 swf Files in a folder /Audio_MP3/ and add the folder to your /site/modules/ directory. Click *check for new modules* in ProcessWire Admin Modules screen. Click *install* for the module labeled: "Audio_MP3". Now you will be on the module config screen. Please make note of the config options and set as you want. How to use Add the Audio field to your Template in Setup > Templates. Add the following code to the template file to get the title list: $modules->Audio_MP3->player['title']; to get the player: $modules->Audio_MP3->player['code']; Create a page using the Template. Drag and drop mp3 or mp3.zip files in the audio field in the Page-Edit-Area. How it works If you store just one File in the Page-Edit-Area the Maxi-Player will be loaded. For 2 or more files the Module will switch to Multi-Player. If you want an alternative title, you can put it in the Description-field of the Audio Field, which is visible after the file upload. Module Configuration - width: Forces the video width. - height: Forces the video height. //only Maxi-Player only one file stored - volume: The initial volume, between 0 and 200. By default set to 50 - showstop: 1 to show the STOP button. - showinfo: 1 to show the INFO button. - showvolume: 1 to show the VOLUME button. - showloading: 'alway','never','autohide') to show the LOADING bar// By default set to 'alway' - showinfo: 1 to show the INFO button. - buttonwidth: The buttons width. By default set to 30. - volumewidth: The width of the VOLUME button. By default set to 30. - volumeheight: The height of the VOLUME button. By default set to 10 - loadingcolor: The color of loading bar in hex format without #//default: ffff75 - sliderovercolor: Hover color of the bar in hex format without # - buttonovercolor: Hover color of buttons in hex format without # feel free to add more configuration options to the module. More information here: http://flash-mp3-player.net/players/multi/documentation/ http://flash-mp3-player.net/players/maxi/documentation/ Need some help! I would like to make the code available via $page->player['code']; but I don't know how. README.txt Audio_MP3.module
    1 point
  17. Hey, I've made this really simple session module that lets to add messages to the session and render it. Here's the complete php file: <?php class SessionMessage extends Process implements Module, ConfigurableModule { public $messages = array(); public static function getModuleInfo() { return array( 'title' => 'SessionMessage', 'version' => 101, 'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.', 'href' => 'http://www.processwire.com', 'singular' => true, 'autoload' => true, ); } public function init() { $this->setFuel('sessionMessage', $this); } static public function getModuleConfigInputfields(array $data){ $modules = Wire::getFuel('modules'); $fields = new InputfieldWrapper(); $field = $modules->get("InputfieldText"); $field->attr('name+id', 'error_class'); $field->attr('value', $data['error_class']); $field->label = "Error class"; $field->description = 'Enter your error class for error handling.'; $fields->append($field); $field = $modules->get("InputfieldText"); $field->attr('name+id', 'success_class'); $field->attr('value', $data['success_class']); $field->label = "Success class"; $field->description = 'Enter your error class for success handling.'; $fields->append($field); $field = $modules->get("InputfieldText"); $field->attr('name+id', 'alert_class'); $field->attr('value', $data['alert_class']); $field->label = "Alert class"; $field->description = 'Enter your error class for alert handling.'; $fields->append($field); return $fields; } //void public function add($type, $message){ //types could be error, alert or success array_push($this->messages, array($type => $message)); $this->session->set('messages', $this->messages); } public function render($clean=true){ $html = ""; $this->messages = $this->session->get("messages"); foreach($this->messages as $array){ foreach($array as $type => $message){ $class = $type.'_class'; $html .= '<div class="' . $this->$class . '">'; $html .= $message; $html .'</div>'; } } $this->session->messages = $this->messages; if($clean == true){ unset($this->messages); $this->session->set('messages', $this->messages); } return $html; } } Installation: 1) Install the module 2) Give classes to each of the default fields: error success alert Usage: To add a message use: $sessionMessage->add('error', 'This is an error message'); To display all messages: echo $sessionMessage->render(); If you don't want the module to erase the messages after being displayed: echo $sessionMessage->render(false); I am currently using this in combination with Zurb Foundation Hope it helps someone. -Harmster
    1 point
  18. Today I just want to show a new page build with ProcessWire. It's nothing fancy but the client is more than happy. http://www.rv-heidenheim.de (german content) The local horse club had an old ugly Flashwebsite which we relaced with a fresh and modern PW site. The goal was to create an easy system to maintain content and to inform people about the club. Behind the scenes: Processwire with ProCache let the site run faster than any horse in the barn. Using the PageLink Field to create a menu structur. Skeletton 960px grid but right now we removed the mediaqueries. We will add the mobile view later. The weater widget uses this jQuery plugin. All widgets in the sidebar are pages and fully configurable by the backend user. A year ago, this was my first Processwire page. But it was never released and we made a complete new second version last month. First time I've used an icon font. Try fontello.com to build your own icon font. The site was designed on a friday evening and only 24 hours later the whole site was done. Using PW it's just a charm to build such small sites and let people insert their content.
    1 point
  19. Here are the new additions Soma's talking about...http://processwire.com/about/news/introducing-processwire-2.3/
    1 point
  20. there are some more padding and margin in px. So I skipped this grid. Because of jackpot.css: the code of html5boilerplate and normalize is used by a lot of grids/frameworks. Also you can pick your needed extras from this resources to complete your own work. Best will be, if you try to build a site with gridiculo. Then you see, if it's ok for you. There are so many grids/frameworks to satisfy nearly everyones need. description of my experience (RWD beginner) in short words: looking for a simple grid (no Bootstrap, Foundation,etc!). Then study the code of some (no px, only em+%). I'm a little bit oldstyle and like to work from desktop to mobile instead of mobile-first. Descision to try Kube at first. Took a simple static ready-designed site (from my demos and test resources) to make it responsive. Work my way through the code. I'm surprised how easy and fast this was finished. I could keep my style and design and make it responsive anyway. Little bit customizing, had to build a responsive navigation. Also important: at the end I changed the px in media-queries to em (to get full text-zoom and site-zoom). @media only screen and (min-width: 480px) and (max-width: 767px) @media only screen and (min-width: 30em) and (max-width: 47.9375em) After that, I tried it with another site. Same experience. The sites are also running in IE8. Yesterday I used the respond.js (which mentioned some posts above) with the demo site. Now IE8 is also getting responsive. Nice to see. Maybe when have more time, I will try this new discovered PocketGrid This is very minimalistic, only 2 classes. But seems to be very flexible. We will see... yes!!
    1 point
  21. Hi Jamie, and welcome. Have you seen the cheatsheet yet: http://cheatsheet.processwire.com/ I am not sure if you are looking to check the template of a specific page, or find a sibling with a specific template. This should help: if($page->template == 'template_name'){ As for checking is a textarea (or any other field contains a specific piece of text)if (strpos($page->textareafieldname, 'specifictext') !== FALSE) echo 'Found';else echo "Not found"; Hope that helps.
    1 point
  22. I find it amusing that twitter requires auth, when pulling public tweets... Boring. </rant>
    1 point
  23. It's also possible to do this: <?php if ($a == 5) { ?> <p>A is equal to 5</p> <?php } ?> //In the above example, the HTML block "A is equal to 5" is nested within an if statement written in the alternative syntax. The HTML block would be displayed only if $a is equal to 5. //The alternative syntax applies to else and elseif as well.
    1 point
  24. ohthanks, Very nice! The only thing I was wanting was a more obvious way to move between "indicators". The sidebar nav works, but I missed it at first being under the rating system. (nitpicking). I love Avenir, nice type choice.
    1 point
  25. Here's an example that should get you there. No time to give a more detailed explanation right now, but go ahead and ask if there's something that seems odd =). Put this into site/modules/PageFirstProductPrice.module and install the module from the admin side (check for new modules first). <?php class PageFirstProductPrice extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Copy first product price', 'version' => 100, 'summary' => 'Copies first product price from a repeater to another field', 'singular' => true, 'autoload' => true, ); } public function init() { $this->pages->addHookBefore('save', $this, 'copyFirstProductPrice'); } public function copyFirstProductPrice($event) { $page = $event->arguments[0]; // we're interested in product pages only if($page->template->name != 'product') return; // copy first product version price, if there is one with a price if(count($page->product_versions) > 0 && $page->product_versions->first()->price) { $page->first_version_price = $page->product_versions->first()->price; } else { // no items wih a price, clear the field // this is needed to keep the field in sync if all items get deleted from the repeater $page->first_version_price = ''; } } } *** Edit *** A bit too hurry as it seems I forgot to mention that my example needs a field called 'first_version_price' in your 'product' template to work. That field should be left hidden as it's populated automatically. And now that you've got a regular field right in your template it's straightforward to sort the product pages in the way you described. And horst seems to have given you the most essential pointer on hooks already, go for it! There's some pretty useful information in the wiki as well. After reading those two and looking at HelloWorld module you'll find yourself hooking away in the promised land of module development in no time.
    1 point
  26. Hi 3fingers, Here is the code that processes the form: https://gist.github.com/outflux3/5690429 here is the form itself: https://gist.github.com/outflux3/5690423 i didn't post the form results, but that's just a table that shows the results; hopefully the processor and form code will help! -marc
    1 point
  27. cmscritic, Am I reading that correctly? http://www.cmscritic.com has been converted to ProcessWire? Edit: Nevermind, Just saw this post immediately after.
    1 point
  28. Wow, this is one sexy module. Thank you! Just installed on my newly processwire'd CMS Critic!
    1 point
  29. I still use FW CS5 and am very happy with it. I couldn't imagine changing to Photoshop. I've looked at Sketch before but never really found it "serious" enough but will have another look as I've heard rave reviews. Thanks for the link Matthew.
    1 point
  30. Good question. This is one of those "one man's meat is another man's poison" sort of situation. There are so many different approaches to doing your template files...No one approach is superior (in most cases ) to another. It is an issue of preference. You can even decide you want all your HTML code with PHP inside in one file. This can result in very long, hard-to-grasp code though. You can decide not to name your includes as .inc but .tpl..PHP will happily include them when asked to do so....Or, you can have as many .inc as you wish to make your head spin trying to guess what is including what . I hope it doesn't confuse you more but have a look at this thread. It has lots of wonderful ideas about approaching your template files. Having .inc files also helps with dynamism. For instance, your website can have the same header throughout but different footers depending on the page being viewed. There can be a sidebar.inc as well, which will only appear in certain pages and show a sub-menu, a featured article, etc.... I am working on a short tutorial part of which I hope to post here soon...(and on my website whenever that materialises ) about visualizing your site structure before you build it. Planning is important in these things. Again, people have different approaches. I like to think diagrammatically, at the whole system level. Such an approach helps me visualise the template approach to adopt for a particular job. For instance, what areas of the website are common/shared? What is unique to some pages? How best can I code/design/plan my templates and template files to achieve what I want making best use of logic, KISS and DRY principles and balancing this against common sense and ease of understanding the code? If I come back to the code in a month's time, or if somebody took over my task, would I/they be able to make sense of it all? Sorry for digressing somewhat
    1 point
  31. My opinion is that a good default behavior is to retain the original filename as much as possible. Otherwise you lose relation to the original file on your computer. Usually when a CMS auto-generates filenames, it's because they don't have another means of relating back to the source (Page/id), are using it to define a sort order, or they don't want to go to the effort of making sure the filename is secure (auto-generated names have no user input). Auto-generated names are the quick and dirty way out for a CMS. Never realized they would actually be desirable. If you have a preference for it to auto-generate names like that, it could certainly be done though. One way to accomplish it would be to make a module that hooks before Pagefile::install and rename the file, and send the new filename to the function. That function receives a single argument of just the filename to add. That filename can be local or http, so you'd only want to attempt a rename if local. public function init() { $this->addHook('Pagefile::install', $this, 'hookPagefileInstall'); } public function hookPagefileInstall(HookEvent $event) { $filename = $event->arguments(0); if(strpos($filename, '://')) return; // don't attempt to rename http-based files $page = $event->object->page; // page that will own the file $info = pathinfo($filename); // PHP's pathinfo() function $n = 0; // find the next available filename do { $n++; $newFilename = "$info[dirname]/{$page->name}-$n.$info[extension]"; // my-page-name-1.jpg } while(is_file($filename)); rename($filename, $newFilename); $event->setArgument(0, $newFilename); // update the argument to the install function } The above was written in the browser and not tested, so may need adjustments before functional. What it does is rename the file before it gets added. The do loop may not actually be necessary here, but that is just to account for the possibility that the directory (PHP's upload dir) already has a file with the target name in it. ProcessWire already takes care of adding numbers to files that are placed in it's own assets/files/ dirs.
    1 point
  32. We've just launched a new company, early days and we needed to get a site out quickly. http://www.milktop.co.uk Still plenty of fiddling to be done and we're pretty busy on other work, just didn't want to be one of those web companies without their own site
    1 point
  33. In 2.3, there are also these two additions (so far, undocumented). Either one returns the number of visible children: $page->numChildren(true); $page->numVisibleChildren; I will be adding these to the API pages, along with all the other 2.3 additions very soon.
    1 point
  34. I've done this before and used the method SiNNuT mentioned. Made the navigation with something like this: for($n = ord('A'); $n <= ord('Z'); $n++) { $letter = chr($n); echo "<a href='{$page->url}$letter/'>$letter</a> "; } Then pulled the items matching the letter from the URL segment like this (just like SiNNuT): $letter = strtoupper(substr($input->urlSegment1, 0, 1)); if($letter >= 'A' && $letter <= 'Z') { $items = $page->children("title^=$letter"); echo "<h2>Letter: $letter</h2>"; if(count($items)) echo $items->render(); else echo "<p>No items found</p>"; }
    1 point
  35. I'm not sure I understand the example. What is NubUsers and NubPages? Also something like $fields->find("page=$r->id"); is completely unfamiliar to me. It seems like there are some parts ProcessWire and some parts something else? Here's a simple example that does exactly that: foreach($page->fields as $field) { echo "<p>"; echo "Field: {$field->name}<br />"; echo "Type: {$field->type}<br />"; echo "Value: " . $page->get($field->name); echo "</p>"; }
    1 point
  36. If you use jquery theres some easy way and do it client side. If you add ?q=searchword to the search result links it's easy possible. Some helpful links To get a url parameter http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery An lightweight plugin to highlight the word on page http://bartaz.github.com/sandbox.js/jquery.highlight.html
    1 point
  37. Thanks for posting Soma, this is an interesting approach and not one I've seen before, but it looks great. The underlying concept and result is similar to the approach I usually use. Since you posted a good description, I'll try to do the same for mine. The only reason you see head/foot files in the default PW profile is because it seems to be simpler for new users to grasp. But I almost never use that approach in my own sites. Like your system, I have a main.php file which is my main markup file. But unlike your system, main.php is included from all the other template files (rather than main.php including them). The other template files focus on populating the key content areas of the site, specific to the needs of the template. Examples of key content areas might include "main" (for center column/bodycopy) and "side" (for sidebar/related info), though often includes several other identified areas. But I'll keep it simple in this case. Here's how it works: basic-page.php <?php $outMain = "<h2>{$page->subtitle}</h2>" . $page->body; if($page->numChildren) $outMain .= $page->children->render(); // list the children $outSide = $page->sidebar; include("./main.php"); main.php <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <h1><?php echo $page->title; ?></h1> <div id='main'><?php echo $outMain; ?></div> <div id='side'><?php echo $outSide; ?></div> </body> </html> The benefit of this approach is that basic-page.php can setup whatever it wants in the key content areas ($main or $side) whether simple like in this example, or something much more complex. I actually prefer for the variables representing the key content areas to be optional. In the scenario above, $outMain and $outSide would have to be defined by every template or they would end up as uninitialized variables in main.php. As a result, I actually use $page as an anonymous placeholder for these variables (making sure they don't conflict with any existing field names) and then let main.php assign defaults if the calling template didn't specify one of them. For example: basic-page.php <?php $page->outMain = "<h2>{$page->subtitle}</h2>" . $page->body; if($page->numChildren) $page->outMain .= $page->children->render(); // list the children // note: no $outSide specified include("./main.php"); main.php <?php // setup defaults when none specified if(empty($page->outMain)) $page->outMain = $page->body; if(empty($page->outSide)) $page->outSide = $page->sidebar; ?> <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <h1><?php echo $page->title; ?></h1> <div id='main'><?php echo $page->outMain; ?></div> <div id='side'><?php echo $page->outSide; ?></div> </body> </html> Final thing to point out here is that main.php is the only template actually outputting anything. Because basic-page.php (or any other template) is determining what's going to go in that output before it is actually sent, your template has the opportunity to modify stuff that you might not be able to with other methods. For instance, the <title> tag, what scripts and stylesheets are loaded, etc. Here's the example above carried further to demonstrate it: basic-page.php <?php // make a custom <title> tag $page->browserTitle = $page->rootParent->title . ": " . $page->title; $page->outMain = "<h2>{$page->subtitle}</h2>" . $page->body; if(count($page->images)) { // display a clickable lightbox gallery if this page has images on it $config->scripts->add($config->urls->templates . "scripts/lightbox.js"); $config->styles->add($config->urls->templates . "styles/gallery.css"); $page->outMain .= "<ul id='gallery'>"; foreach($page->images as $i) { $t = $i->size(100,100); $page->outMain .= "<li><a href='{$i->url}'><img src='{$t->url}' alt='{$t->description}' /></a></li>"; } $page->outMain .= "</ul>"; // add a note to $page->title to say how many photos are in the gallery $page->title .= " (with " . count($page->images) . " photos!)"; } if($page->numChildren) $page->outMain .= $page->children->render(); // list the children include("./main.php"); main.php <?php // if current template has it's own custom CSS file, then include it $file = "styles/{$page->template}.css"; if(is_file($config->paths->templates . $file)) $config->styles->add($config->urls->templates . $file); // if current template has it's own custom JS file, then include it $file = "scripts/{$page->template}.js"; if(is_file($config->paths->templates . $file)) $config->scripts->add($config->urls->templates . $file); ?> <html> <head> <title><?php echo $page->get('browserTitle|title'); // use browserTitle if there, otherwise title ?></title> <?php foreach($config->styles as $url) echo "<link rel='stylesheet' type='text/css' href='$url' />"; foreach($config->scripts as $url) echo "<script type='text/javascript' src='$url'></script>"; ?> </head> <body> <h1><?php echo $page->title; ?></h1> <div id='main'><?php echo $page->get('outMain|body'); // use outMain if there, or body otherwise ?></div> <div id='side'><?php echo $page->get('outSide|sidebar'); // use outSide if there, or sidebar otherwise ?></div> </body> </html> More than half the time, I'll actually just re-use page variables like $page->body and $page->sidebar rather than $page->outMain and $page->outSide. That way there's no need to consider defaults, since $page->body and $page->sidebar untouched technically are defaults. <?php $page->body = "<h2>{$page->subtitle}</h2>" . $page->body . $page->children->render(); But technically you've got a little more flexibility using your own self-assign anonymous variables like outMain and outSide, so figured I'd use that in the examples above. outMain and outSide are just example names I came up with for this example and you could of course name them whatever you want.
    1 point
×
×
  • Create New...