Jump to content

diogo

Moderators
  • Posts

    4,287
  • Joined

  • Last visited

  • Days Won

    79

Community Answers

  1. diogo's post in Maximum "Pages Creations" with API was marked as the answer   
    Check also if the limitation is not on the FB API side. I remember that I had to do the same with youtube, but YT allowed me to call a limited amount of videos on the same request.
  2. diogo's post in List of latest blog posts on homepage was marked as the answer   
    Oh, of course. When using this kind of foreach structure you have to reopen PHP to echo your object properties. You can open it with <?php or echo them with the shorter version <?=
    <?php foreach ( $pages->find('template=single, limit=5') as $single ):?>     <div class='post'>               <div class='content'>              <a href='<?=$single->url?>'><h3><?=$single->title?></h3> </a>           </div>          </div>       <? endforeach; ?> You can also use the most common PHP structure, where you don't go in and out of php. Your choice.
    Anyway, I think you would benefit a lot from studying the basics of PHP while using ProcessWire.It's not hard at all and will making everything more clear for you.
  3. diogo's post in Parameterized template was marked as the answer   
    Short answer because on mobile. Look on the docs for url segments
  4. diogo's post in Will the database structure of PW 3 change until release? was marked as the answer   
    I guess your problem with the sentence in the readme is the word should. Ryan was already explicit in saying that he believes that the devns branch is safe for new projects, even the download button in the site states that: "The newest 3.x dev version, great for testing, new projects or development." Honestly, if these aren't enough for you, maybe you should play safe and stick to the stable branch.
  5. diogo's post in incomplete array was marked as the answer   
    Try:
    <?php foreach($page->children as $child):     foreach($child->images as $image):         echo $image->url;     endforeach; endforeach;  ?> I kept the code similar to what you had so you understand the differences, but way of writing PHP is more suitable if you want to alternate PHP and direct HTML. For a simple echo it's better to just use brackets.
    I'm actually surprised that you don't get a PHP error with that code 
  6. diogo's post in Multilanguage Support doesn´t work. URL? was marked as the answer   
    Did you add the url name for each language on the homepage settings?
  7. diogo's post in repeater inside repeater was marked as the answer   
    See here for the reason why you can't https://processwire.com/talk/topic/3927-can-you-have-a-repeater-field-within-a-repeater/
  8. diogo's post in echo an id from repeater was marked as the answer   
    Welcome to the forum Paschalis.
    This is not the usual way of getting repeater Items, but since you know the ID and repeaters are pages just like any other page, it's as easy as:
    $pages->get($repeater_id)->title
  9. diogo's post in basic-page.php was marked as the answer   
    It's in the _func.php file, which is included in _init.php, which is automatically prepended to all template files
    https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/templates/_func.php#L25
  10. diogo's post in Holder/Page Pattern was marked as the answer   
    Hi cssabc123, welcome to the forum!
    Very quickly and resumed because of time constraints:
    - Holder
      - article 1
      - article 2
      - ...
    //holder.php foreach ($page->children as $article) {     echo "<h2>{$article->title}</h2>";     echo "<p>{$article->summary}</p>";     echo "<a href='{$article->url}'>Read more</a>"; } //article.php echo "<h2>{$article->title}</h2>"; echo "<p>{$article->body}</p>"; I left lots of things out,like pagination, that you can read about here https://processwire.com/blog/posts/processwire-2.6.18-updates-pagination-and-seo/
    But hope you get an idea.
  11. diogo's post in Get "like children" render nav was marked as the answer   
    $page->children is an array, you can't echo it directly:
    foreach($page->children as $child) {     echo $child->title; }
  12. diogo's post in Working with tags was marked as the answer   
    Also, you can remove the current page from the array to avoid the IF check inside the loop
    $results = $pages->find("tags={$page->tags}")->remove($page)->shuffle(); Or, do the same as above with one less method:
    $results = $pages->find("id!={$page},tags={$page->tags}")->shuffle();
  13. diogo's post in How to use a variable from one template in another was marked as the answer   
    @elabx, not possible. We are in one of the interests pages at this point.
    --
    You have only two ways of passing info to the future page when pressing a url: the url itself or session. With session there is no way to create a permanent shareable page, so i would go for the url.
    you can do this with url segments or using a get in the url referring to the place.
    --
    I would simulate with url segments that interests is at the same level of the tree as (do, see, etc) and link to there instead, leaving the interests pages without a template file. You could do it like this:
    <?php foreach ($page->interests as $i) { $place = $page->closest("template=place"); //or whatever works $url = $place->url . "/interest_" . $i->name echo "<li><a href='{$url}'>{$i->title}</a></li>"; } ?> On the template from the places pages you would have something like (rough draft):
    if ($input->urlSegment1) {     if (!substr($input->urlSegment1,0,9) == "interest_" ) throw new Wire404Exception();         $reduced = str_replace("interest_", "", $input->urlSegment);     $sanitized = $sanitizer->name($reduced);     $int = $pages->get("name=$sanitized");     $pois = $pages->find("template=poi, interests=$int");     $content .= renderNav($pois); } Edit: And welcome to PW!
    Edit2: corrected typo
  14. diogo's post in Saving a field [ I am retarded |:\ ] was marked as the answer   
    You are getting the general field itself, not the field in that page. Try this instead:


    $other_page = $pages->get("selector_for_the_page");
    $other_page->setOutputFormatting(false);
    $other_page->bestelnummer = $other_page->bestelnummer++;
    $other_page->save('bestelnummer');

    To understand the second line check this: http://cheatsheet.processwire.com/page/built-in-methods-reference/page-setoutputformatting-true-false/
  15. diogo's post in Page field, or similar, but for repeater rows? was marked as the answer   
    They are pages. Look for them under "Repeaters" inside the admin page in the tree.
    Repeater pages are under a page with the name "for-page-1234" (1234 is the ID of the page that holds the repeater field) under a page named "for-field-123" (being 123 the id of the repeater field. You can see it o  the URL when editing the field). This means that you can easily get all pages from a repeater field in a page by using the selector:
    $pages->find("parent=/processwire/repeaters/for-field-123/for-page-1234") Or even construct that selector dynamically when needed:
    $pages->find("parent=/processwire/repeaters/for-field-130/for-page-{$page->id}")
  16. diogo's post in Adding static content to a template was marked as the answer   
    Hi KunGu, welcome to the forums!
    Eheh, you chose the most difficult way to start I don't thing that's a bad thing but I would suggest that you also do some test with the direct output, since it's the simplest to understand and most common way in CMS integration. Just to have a feeling of how it works.
    With the delay output, you got it right, Heredoc is one way to go. Other way is to concatenate the html pieces like this:
    // ultra simplified example $myVariable = "<p>"; $myVariable .= "content"; $myVariable .= "</p>"; You can also include the content of an external file into a variable in two ways:
    ob_start(); include('slider.inc'); $myVariable = ob_get_clean();   or:
    $myVariable = file_get_contents('slider.inc')
  17. diogo's post in Getting fields in a fieldset was marked as the answer   
    Well, the fields are not really inside the fieldset, so you can’t get them in an easy way. What you can is look for the fieldset_open and get all the fields after that and before fieldset_close. Have to go, so no code example, I’m sure you’ll get it from here
  18. diogo's post in How get all fields of every page? was marked as the answer   
    Adrian, I don't think that does what was asked. $fields will will get all the fields that you created, not the ones that are in the pages.
    hsanabria, you have to identify which fields represent other pages. Using your example:
    foreach($page->fields as $field) {     $fieldValue = $page->get($field->name);     echo $field;     foreach($fieldValue as $innerPage) { // if value of the field is a page array, we can iterate it         foreach($innerPage->fields as $innerPageField) {               $innerPageFieldValue = $innerPage->get($innerPageField->name);               echo $innerPageFieldValue;         }     } } Of course it would be much simpler to create a general function that iterates the fields of a page and call it recursively if that field is a page array. But I hope this serves as an example.
  19. diogo's post in Limit selector not working as expected was marked as the answer   
    The problem is that you are choosing 6 from each category, and not 6 from all. The ideal would be to get all the portfolio pages with one selector. There are several ways of doing this, the one that looks more logical in your case is to select by template:
    $portfolio_pages = $pages->find("template=portfolio-item, limit=6, sort=random"); foreach($portfolio_pages as $item) {     // echo here }
  20. diogo's post in Import pages/files from XML files was marked as the answer   
    As I understand you are creating a page per property. In that case yes, straight in the foreach. Unlike find(), get() stops immediately after finding the first occurrence that matches the selector and keeps only that one object in memory, so it's very light and surprisingly fast.
    Edit: as for querying the db every time, I don't see a better solution. The alternative would be to loop through all the properties in the XML to collect the references, query the database to check which ones are still not there, collect them, and loop again the XML only using those... Not sure if this would be more effective.
  21. diogo's post in How can I add an .href security exception? was marked as the answer   
    Welcome to the forum!
    You could of course add an exception to that file only on the href, but IMO the best way to do this is to have that file as a normal PW template and create a page with it, then, just call the page instead of the file:
    example.com/utilities/xcrud (or whatever you want)
  22. diogo's post in Text Area outputting P tags was marked as the answer   
    Check if you have the "convert to HTML entities" textformatter set.
  23. diogo's post in Add class "current" to all parents in a multi-level menu was marked as the answer   
    Not tested, but try this:
    $page = wire('page'); $out .= $item->id == $page->id || $page->parents()->has($item) ? "<li class='current'>" : "<li>";
  24. diogo's post in Pagefield type - Get title was marked as the answer   
    Is this a multiple page field? In that case you would have to iterate it with a foreach or get the first one with first()
    <?php foreach($page->food_types as $ft) {     echo $ft->title; } ?> or
    <?=$page->food_types->first()->title ?>
  25. diogo's post in Stuck with $pages->get("/path/to/page/") inside <a href=""></a> was marked as the answer   
    Please think for 5 seconds before posting! You are opening a php tag inside a php tag. Joss suggested you do that because you weren't clear if you were doing this inside or outside a php tag. You have two choices:
    <!-- Outside the PHP tags--> <div id="button3" class="button_style"><a href="<?=$pages->get("/kontakt/")->url ?>">kontakt</a></div> or
    <?php // inside the PHP tags. You are using single quotes, so you can't echo variables without closing them echo '<div id="button3" class="button_style"><a href="' . $pages->get("/kontakt/")->url . '">kontakt</a></div>'; ?>
×
×
  • Create New...