Jump to content

Macrura

PW-Moderators
  • Posts

    2,756
  • Joined

  • Last visited

  • Days Won

    40

Community Answers

  1. Macrura's post in Template (php) was marked as the answer   
    1.)
     
    "<article> <h2>{$page->title}</h2> <header class='news-meta'><strong>Date : </strong>{$page->publish_date}</header> <div class='news-content-text'> <p>{$page->summary}</p> </div> <div class='article'>{$page->body}</div> <p><img src='{$image->url}' alt='{$image->description}'></p> </article>";  
    _main.php should be the global layout; the templates just populate the content variable which is within the content area of the '_main' layout.
    $page->body is the "body" field (the one with the Rich Text Editor)
    Closing brackets are not needed and should always be left out when the file ends with php code: https://processwire.com/api/coding-style-guide/#2-general
     
     
     
  2. Macrura's post in Colors in ckeditor? was marked as the answer   
    actually this is in the core, all you need to do is add these to your toolbar (you don't need to add any plugins):
    so where your first line would look like this out of the box:
    Format, Bold, Italic, -, RemoveFormat you can change it to be like this:
    Format, Bold, Italic, Underline, -, RemoveFormat, -, TextColor, BGColor
  3. Macrura's post in Call to non-object width() was marked as the answer   
    also to be safe you should make sure that there is a logo..
    foreach ($pages->get("template=case-studies")->children("logo!=") as $child) {
  4. Macrura's post in Add a custom button or link to backend template was marked as the answer   
    Not sure if this helps, but for custom buttons i have recently made large usage of Kongondo's Runtime Markup field to create custom buttons and many other custom things (special information, tables of other pages, etc) to use on the page edit screen.
  5. Macrura's post in How to detect image width, and if smaller than x, display at original size? was marked as the answer   
    if(count($page->images)) {
    $images = '';
    foreach($page->images as $image) {
    if($image->width < 801) {
    $image = $image;
    } else {
    $image = $image->width(800);
    }
    $images .= "<img src='{$image->url}' /><br />";
    }
    }

  6. Macrura's post in putting a checkbox in a column of markupadmindatatable, outputted a plain text was marked as the answer   
    maybe you need this?
    $table->setEncodeEntities(false);
  7. Macrura's post in Sorting results then grouping was marked as the answer   
    yes, there is an extensive discussion of that here, with code of how to achieve that:
    https://processwire.com/talk/topic/4991-sub-arrays-dates-times-and-pure-hell/
    other options:
    https://processwire.com/talk/topic/6733-better-way-to-finding-all-years/#entry65975
    https://processwire.com/talk/topic/11690-display-results-with-a-year-heading-using-datetime-field/?p=108709
  8. Macrura's post in Are PageTable nestable? was marked as the answer   
    It should work
  9. Macrura's post in Accidentally deleted config.php! Don't know userAuthSalt, Now what...!? was marked as the answer   
    Hi douglas81,
    I'm not an expert on this, but i think what I might try in this case would be to:
    1.) rebuild your config.php - maybe from a vanilla install, or another site;
    2.) change the password of the superadmin from the API, which would then presumably use the new userAuthSalt;
    <?php $admin = $users->get('admin'); // username of superadmin $admin->of(false); $admin->pass = 'yo12345'; // put in your new password $admin->save();
  10. Macrura's post in Sending Form Emails was marked as the answer   
    you would retrieve the email address like:
    $emailTo = $page->Header_select->contactAddress; BTW - you are mixing up your cases, your variable is camelCase, your page select is underscore_case with the first letter capitalized, and your page field is camelCase.
    For clarity and ease I would recommend at least being consistent with your field naming, e.g. always use underscore_case (no caps) or camelCase.
  11. Macrura's post in Remove duplicates in a foreach loop (but count them) was marked as the answer   
    you mean counting like this?
    $kids = $pages->find("template=poi, has_parent=$page"); $interests = new PageArray(); foreach ($kids as $k)  $interests->import($k->interests); $iTotal = count($interests); foreach ($interests as $i) $i->useCount = count($pages->find("interests=$i")); echo "<h3>Interests ($iTotal)</h3>"; echo '<ul>'; foreach ($interests->sort("-useCount") as $i) {     echo "<li><a href='interest/$i->name'>$i->title</a> ($i->useCount)</li>"; } echo '</ul>';
  12. Macrura's post in How to limit the number of results returned from $pages->find to a particular child level? was marked as the answer   
    to put it simply, you only want descendants of the current page,
    $allChildren = new PageArray(); foreach($page->children() as $parent) {    foreach($parent->children() as $child) $allChildren->add($child); } $assignments_find = $allChildren->find("template=quiz|challenge|assignment, course_name_from_list=$page, sort=assignment_due_date");
  13. Macrura's post in Remove link from specific top-level page with child pages was marked as the answer   
    just tested my method and works perfectly. you sure you did it right?
    glad i know this works now, gonna come in handy!
    1.) Create new field, call it url_override
    2.) Add to your template
    3.) on the Page C page, type a # into the field
    4.) in your treemenu options make sure you have this:
    'item_tpl' => '<a href="{url_override|url}">{title}</a>',
  14. Macrura's post in Cleaner way of doing this? was marked as the answer   
    maybe something like this?
    if($page->city) { $setCity = $page->city; $cityURL = $sanitizer->pageName($page->city); echo " <span class='topNav'> <a class='' href='/gyms' title='Gyms'> <i class='fa fa-chevron-left'></i></span> All Gyms</a> <span class='topNav'> <a class='' href='/gyms/{$cityURL}-gyms/' title='{$setCity} Gyms'> <i class='fa fa-chevron-left'></i></span> $setCity Gyms</a> <span class='topNav'> <strong> <i class='fa fa-chevron-right'></i></span> {$page->title} </strong> "; $randomGym = $pages->find("template=listing-gym, city=$setCity")->getRandom(); if($randomGym->id) echo " <a title='{$randomGym->title}' href='{$randomGym->url}'><i class='fa fa-random'></i> Random Gym</a>\n"; }
  15. Macrura's post in Use HannaCode to fetch an include file was marked as the answer   
    @peter knight -
    this always works for me..
    include($config->paths->templates . "hannas/minislidegal.php"); this way you can edit your hanna codes right in your ftp/editor...
  16. Macrura's post in New pages not displaying was marked as the answer   
    it's working for me; if i'm logged in, and i go to the root URL, i see processwire.
    if i logout and click home icon, i see the non-PW site.
    make sure that you are not already loading the index.html page because if that is loaded, you are already bypassed PW
  17. Macrura's post in Output name from select field was marked as the answer   
    @laban, just change the page select from a multi to single and it should fix your issues
  18. Macrura's post in Mega Menu was marked as the answer   
    here's a first try though untested as of yet...
    worked on this a bit...
    /**  *  render markup menu for bootstrap nested navigation  *  * @param  PageArray  $pa     pages of the top level items  * @param  Page  $root   root page optional, if you use other root than home page (id:1)  * @param  string  $output for returned string collection  * @param  integer $level  internally used to count levels  * @return string          menu html string  */ function renderChildrenOf($pa, $root = null, $output = '', $level = 0) {          if(!$root) $root = wire("pages")->get(1);     $output = '';          $level++;     foreach($pa as $child) {         $has_children = count($child->children()) ? true : false;         $opening = '';         $closing = '';                  if($has_children && $child === $root) {             $output .= "\n\t<li><a href='{$child->url}'>{$child->title}</a></li>\n";         }                  if(!$has_children) {             $output    .= "\t<li><a href='{$child->url}'>{$child->title}</a></li>\n";         }                  if($has_children && $child !== $root) {             if($level == 1) {                 $opening  = "\t<li aria-haspopup='true'>\n<a href='{$child->url}'>{$child->title}</a>\n<div class='grid-container12'>\n";                 $closing  = "</div>\n</li>\n";             }             if($level == 2) {                 $opening = "\n<div class=\"grid-column3\">\n<h4>{$child->title}</h4>\n<ul>\n";                 $closing = "</ul>\n</div>\n";             }         }                  $output .= $opening;                  // If this child is itself a parent and not the root page, then render its children in their own menu too...         if($has_children && $child !== $root) {             $output .= renderChildrenOf($child->children(), $root, $output, $level);         }                  $output .= $closing;     }            return $output . "\n"; } it's also easier in this case to specify the outer markup and let the function do the rest..
    $root = $pages->get(1); $pa = $root->children(); $pa->prepend($root); echo '<ul class="mega-menu">'; echo renderChildrenOf($pa,$root); echo '</ul>'; but probably you'll need to work on it because this really only works with that exact page tree structure..
  19. Macrura's post in Use another template in runtime was marked as the answer   
    actually you can just show different content based on the request type; so if you are doing a quick view, then you show that with Ajax; if you are linking to the page you show the page code;
    i'm doing that here:
    http://www.katonahartcenter.com/student-showcase/
    and here:
    http://www.charleswuorinen.com/compositions/
    so on your template:
    <?php if($config->ajax) { ?>
    show your markup for the quickview here
    <?php } else { ?>
    show your normal page code
    <?php } ?>
    so you don't need the quickview part of the URL
  20. Macrura's post in find repeater pages was marked as the answer   
    yes, we can help!
    you just need to add check_access=0 to your selector
    http://cheatsheet.processwire.com/selectors/built-in-page-selector-properties/check_access-0/
  21. Macrura's post in Search Template Adding All Fields or Some was marked as the answer   
    it should work, you should be able to put as many fields there as you want to return results;
    you can also do stuff like this, if you have different fields on different templates: also notice the % sign
        $matches = $pages->find("title|body%=$q, template=basic-page|faculty|class");     $kmatches = $pages->find("keywords=$q, template=class");     $matches->import($kmatches)->sort('template,title');
  22. Macrura's post in Two fields on a page - Best way to replace old field value with another one was marked as the answer   
    you mean like this?
    if($product->sc_price_drop) { $out .= '<del>' . $product->sc_price . " €</del>"; $out .= number_format($product->sc_price_drop) . " €"; } else { $out .= ($product->sc_price ? number_format($product->sc_price) . " €" : $na); }
  23. Macrura's post in Sub arrays, dates, times and pure hell was marked as the answer   
    hey Joss - maybe see if this is better... still untested:
    <? function events() { // get all of the events $events = wire("page")->events; //gets the repeater field $years = array(); $out =""; // find the array of years for all events foreach ($events as $event) { $years[]= date("Y", $event->getUnformatted("event_start_time")); // add properties event_year and event_month to the $event object $event->event_year = date("Y", $event->getUnformatted("event_start_time")); $event->event_month = date("m", $event->getUnformatted("event_start_time")); } $years = array_unique($years); asort($years); // for testing // print_r($years); // print_r($events); foreach($years as $key => $year) { // Output the year $out .="<h2>{$year}</h2>"; // find the array of events this year and put into new array $year_events $year_events = $events->find("event_year=$year"); // print_r($year_events); // loop through the events for this year and add the months to the array $months = array(); foreach ($year_events as $year_event) { $months[]= date("m", $year_event->getUnformatted("event_start_time")); } $months = array_unique($months); asort($months); // print_r($months); // loop through the months and find events for the month foreach($months as $key => $month) { // Output the month as a number $out .="<h3>{$month}</h3>"; // filter only the events for this month, from the $year_events array. $month_events = $year_events->find("event_month=$month"); // print_r($month_events); foreach($month_events as $e) { $out .="<p>{$e->event_who}</p>"; } // end foreach events for this month } // end foreach months } // end foreach years echo $out; } ?> *maybe joss or a moderator could mark this as best answer?
  24. Macrura's post in search 'rar' and 'tar' result in 404 was marked as the answer   
    This one is solved as far as the 404 - i just received a reply from the hosting people:
    I confirmed that those were blocked by our mod_security rules. still would be good to figure out about sanitizing keywords fields the correct way...
×
×
  • Create New...