Jump to content

davo

Members
  • Posts

    283
  • Joined

  • Last visited

Everything posted by davo

  1. Hi I usually know how to sort an array of pages but i'm a little stuck this time. I'm sure it's pretty obvious. foreach($page->children as $child) { $class = $page === $child ? " class='on'" : ''; if($child->DMC_represented!=0) { echo "<li> <a$class href='{$child->url}'> <span class='label label-default'> {$child->DMCcontact_Country}</span> {$child->title}</a></li>"; } } How would I sort the results in this case A-Z by the DMCContact_Country field please? David
  2. I think I solved it; although i'm sure someone will be able to see far smarter way to achieve this: $region = $page->title; echo "<H3> you are looking in $region </H3>"; $items = $pages->find("parent=/region/$region, template=dmc, DMC_map!='' sort=title"); $map = $modules->get('MarkupGoogleMap'); if($items!=''){ echo $map->render($items, 'DMC_map', array('height' => '500px')); }
  3. I have a number of pages which belong to countries. I've arrange the urls structure like this: http://dmc.dudmc.com/region/europe/weichlein-tours-and-incentives/ I've purposely not included the region as a field in the page template as I new it would be hanging off the right branch or my url tree as above. I've just got myself into a bit of a pick about how to access the segment 'europe' as a variable from other pages. I'm trying to add it into this call: $items = $pages->find("template=dmc, DMC_map!='', sort=title"); $map = $modules->get('MarkupGoogleMap'); echo $map->render($items, 'DMC_map'); I'm calling this from the europe page to list on the map all child pages of the current page. So i'm trying it like this: $region = $page->title; echo "<H3> you are looking in $region </H3>"; $items = $pages->find("template=dmc, DMC_map!='', parent=$region, sort=title"); $map = $modules->get('MarkupGoogleMap'); echo $map->render($items, 'DMC_map'); but it complains i've not escaped my selector?
  4. very nice - easy on the eye!
  5. Thank you. I'm all self taught so I'm an expert in none but a jack of all. Thanks
  6. Fantastic - works like a charm. I'll keep this function handy for other projects. I've just got to slowly read through it so i'm sure i understand it all. Thanks
  7. I almost though I had it then. I tried this: function mymaketable($pageid){ $current_page = wire('pages')->get($pageid); echo "<table class='table table-striped'>"; foreach($current_page->fields as $field){ if (strpos($field,'DMCstats_') !== false) { if(is_array($field)){ echo "<tr> <td>{$field->label}</td><td>"; foreach ($field as $f) { echo "Its an array {$f->title}, " ; } }else{ echo "<tr> <td>{$field->label}</td> <td>Not Array {$current_page->$field}</td> </tr>"; } } } echo "</table>"; } but it spat the array out treating it like it wasn't an array. Like this: Specialise In Not Array 1009|1010|1011|1012|1013|1025|1026|1027|1028|1029|1030|1031 http://dmc.dudmc.com/dmc/weichlein-tours-and-incentives/ This confused me a little bit as it looks like it is an array, but its met my else statement instead?
  8. Thank you so much; that works really well. There's just a couple more things i need to do to this function to make it FULLY make the table. Not all of the fields are text or integers. Some of them are pages in an array. I've been manually calling them like this: echo" <table class='table table-striped'> <tr><td>Specialise In</td><td>"; $specials = $page->DMC_Specialise_In; foreach ($specials as $special) { echo "$special->title, " ; } echo "</td></tr>"; So some how I need to get pw to recognise if it has an array and do an IF if that's the case else do like we'd done above. I suppose I could run the foreach on our function above and if it's a single row it should produce the field content and if it's an array it would loop until done? With my primitive skill i could probably bash that together, but it needs to treat the two different yes? I'd need one to output the value of the field and the former to output $field->title ? I am getting a little over my head here but i'm just about managing to keep up i think. If this has moved to far away from the original question I'm happy restart it in a new thread; or maybe it will benefit other novices to see how a simple function can progress..
  9. Got there at last, looks like this: <?php function maketable($field,$pageid){ $current_page = wire('pages')->get("$pageid"); $fieldname = wire('fields')->$field->label; echo "<tr><td> $fieldname </td>"; echo "<td>{$current_page->$field} </td></tr>"; } ?> A tidy little function so I don't have to write out every call to every row in my table, just call the function multiple times. I'm sure there's an even fancier way to repeat this automatically for every field prefixed DMC_ , but that'll have to be for another day. Thanks for all your help.
  10. One for the morning now but thanks
  11. Bingo - did it like this: <?php function maketable($label,$field,$pageid){ $current_page = wire('pages')->get("$pageid"); echo "<tr><td> {$current_page->$field->label} </td><td>{$current_page->$field} </td></tr>"; } ?> i can sleep now tonight - cheers.... but before i do go to sleep, could i make my function even simpler and get the label of the field as i've done above so it's one less thing I have to pass it? I thought I would have been able to do it as above but it doesn't output anything. thanks for all your help.
  12. Thanks; I think i understand where you're going with this. So i've adapted the function as you said: <?php function maketable($label,$field,$pageid){ $current_page = wire('pages')->get("$pageid"); echo "<tr><td>label $label</td><td>page is $current_page and the field is $field and it should call.. $current_page->$field </td></tr>"; echo "label: $label<br />field: $field<br />pageid: $pageid<br /> actual field: $current_page->DMC_Capital"; } ?> and added an extra value. The output of your debug code was correct: label: GMT field: DMC_Capital pageid: 1022 actual field: Berlin label GMTpage is 1022 and the field is DMC_Capital and it should call.. 1022->DMC_Capital The problem I have is $field is the name of the field that i'm trying to call, but as soon as I add it like this $current_page->$field it doesn't interpret it correctly and instead returns this: 1022->DMC_Capital. As you can see when I explicity name the field like this $current_page->DMC_Capital it returns the correct output. Thanks for your help with this. The page i'm playing with is here: http://dmc.dudmc.com/dmc/weichlein-tours-and-incentives/
  13. ok, i'm still on my steep learning curve here and trying to be really smart with a function to cut out some coding. If you have a look at my novice code here i think it will be obvious what i'm trying to achieve... <?php function maketable($label,$field,$pageid){ $current_page = wire('pages')->get("$pageid"); $field_display = $page->$current_page->$field; echo "<tr><td>label $label</td><td>page is $current_page and the field is $field and it should call.. $field_display $current_page->$field </td></tr>"; } ?> Is it obvious? So, it's the last bit i'm coming unstuck with. $current-page->$field. If i've got this right, $field should be displaying the field name that i'm passing it from the page, but of course pw is interpreting it literally as text. I appreciate that it's because it should be expecting it like this $current_page->field. So I need to get it to place the value of $field in there, not literally.
  14. davo

    custom page

    thanks for the reply. Unfortunately that didn't solve it. It's an odd problem as all my other processwire sites on the same server work without problem. The stats directory is set to 755 and has a number of files in it for reading.
  15. I've adapted a simple menu script to show child items of the current page and output them as a menu list like this: function kiddiMenu(){ // Create the top navigation list by listing the children of the homepage. // If the section we are in is the current (identified by $page->rootParent) // then note it with <a class='on'> so we can style it differently in our CSS. // In this case we also want the homepage to be part of our top navigation, // so we prepend it to the pages we cycle through: $current_page = $pages->get("/planning-your-journey"); $homepage = $current_page; $children = $homepage->children; echo "<ul class='' >"; foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; echo "<li><a$class href='{$child->url}'><span class='l'></span><span class='r'></span><span class='t'>{$child->title}</span></a></li>"; } echo"</ul>"; } All is good if i write it into the template, but i'm trying to be tidier this time around and write it as a function that can be called from a number of templates. I'm not very experienced with this, but when I turn it into a module and call it from A template the browser complains like this: Error: Call to a member function get() on a non-object (line 47 of /var/www/clients/client13/web35/web/site/templates/myfunctions.inc) Could someone help please. Or should I just write it in the template file? cheers David
  16. Thanks - looks like it was a module I had running which slides through images. I've uninstalled it and although not very pretty now at least avast lets it through again. Needs converting to PW any how!
  17. Cheers mark, that's quite an old site based on joomla. The site seems to function fairly normally (although not very pretty!), does avast give any clue as to what or where the trojan might be? I did have a similar complaint from eset on another site and then it went away after a day.
  18. My server generates site usage stats in a directory called /stats But when i navigate to this page, processwire takes over and complains the page is not found. How do i get processwire to forget it's own page structure for a moment and just allow this directory through? And, just out of interest, how is pw keeping control in the directory structure? Is it through htaccess file or something? Cheers db
  19. I'm really please with my first attempt at a site: http://www.garagesalefinder.co.uk It uses the map module which was fairly easy to implement; Uses the simple news tutorial which I've also adapted to make a cool links block; Uses a Pete's email to page module that I've also adapted to feed straight into the simple news tutorial; Anyway, I'm very pleased with my first little project Thanks to everyone who has helped me on the forum
  20. Nice! What do you use to create the template? All from scratch?
  21. Or I could turn it on for the correct template. Thank you. Solved!
  22. Thanks Diogo That sounded like it was going to work; I edited the template settings and Allow Page Numbers? and I also checked Allow URL Segments? Was this what you meant? sadly this didn't work; any other ideas please?
  23. So I've followed a number of tutorials this week and combined them together making some really cool adaptions. But, the part that I can't get to work is the simple news tutorial: http://wiki.processwire.com/index.php/Simple_News_System I've used the functions page as below and pagination, is the only part that I've not messed about with; but in reality, the only parts of the code i've changed is the sort order where I've asked it to be sorted by reverse natural sort order I think; this is so I get the newest news articles first. The pagination function just seems to return the same page each time. <?php /* LIST ARTICLES This displays a list of articles in div containers on the news-index page. */ function newsList(){ // Grab the page name from the url $thisCategory = wire("page")->name; // If the category is not called "news" then output the category name as a selector for the find. if($thisCategory !="news") { $category = "article_category.name=" . $thisCategory; } // Get the news posts - limited to ten for later pagination $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, sort=-sort, limit=10"); $out =" "; //Loop through the pages foreach($newsposts as $newspost){ $out .="<div class='clearfix'><hr>"; $out .="<BR><a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>"; if($newspost->article_thumbnails){ $out .="<a href='{$newspost->article_thumbnails->url}' class=''>"; $out .="<img class='' src='{$newspost->article_thumbnails->getThumb(listingthumb)}'>"; $out .="</a>"; } // $out .="<a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>"; $out .="<p>{$newspost->article_introtext}<a href='{$newspost->url}'> Read more...</a></p><br>"; $out .="</div>"; } // Pagination $out .="<div class='pagination'>"; $out .= $newsposts->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'listMarkup' => "<ul>{out}</ul>", 'itemMarkup' => "<li>{out}</li>", 'linkMarkup' => "<a href='{url}'>{out}</a>" )); $out .="</div>"; echo $out; } /* CATEGORIES LIST This lists available categories */ function categoriesList(){ $categories = wire("pages")->find("parent=/categories/, template=TUT_news.index, sort=title"); $out =" "; foreach($categories as $category){ $out .="<li><a href='{$category->url}'>{$category->title}</a></li>"; } echo "<ul>$out</ul>"; } /* DISPLAY ARTICLE This displays the article on the news page. You can change the <a> class if you are using a lightbox */ function newsDisplay(){ $newspost = wire("page"); $out =" "; if($newspost->article_thumbnails){ $out .="<a href='{$newspost->article_thumbnails->url}' class=''>"; $out .="<img class='align_right' src='{$newspost->article_thumbnails->getThumb(thumbnail)}'>"; $out .="</a>"; } // $out .="<h2>{$newspost->title}</h2>"; $out .=$newspost->article_maintext; echo "<div class='clearfix'>$out</div>"; } /* first attempt at newsblock */ function newsblock(){ // Get the news posts - limited to ten for later pagination $blocknewsposts = wire("pages")->find("parent=/news-articles/, article_thumbnails!='', template=TUT_news, sort=-sort, limit=12"); $out =" "; //Loop through the pages foreach($blocknewsposts as $blocknewspost){ // $out .="<div class='clearfix'>"; if($blocknewspost->article_thumbnails){ $out .="<a href='{$blocknewspost->url}' class=''>"; $out .="<img class='' src='{$blocknewspost->article_thumbnails->getThumb(listingthumb)}'>"; $out .="</a>"; } // $out .="</div>"; } echo $out; } ?> The page renders like this: http://www.garagesalefinder.co.uk/news/ I understand most of the code, but I do get a little lost understanding the pagination code, which makes it difficult for me to debug. I've made an image block at the end of it too which i've very please with, but the problem was there prior to that.
  24. I'm no expert, but you could try doing what I did a couple of posts above. I bashed my address fields together and let it to geocoding server side.
  25. Bingo! Yes it does indeed. Thank you. I'm assuming this is because my email was encoded as plain text and not html
×
×
  • Create New...