-
Posts
450 -
Joined
-
Last visited
Everything posted by bwakad
-
Can someone explain this for me: $page->fields. API states: All the Fields assigned to this page (via it's template, same as $page->template->fields). Returns a FieldsArray. But I only receive back 1. At first it will give me the template which is used. When using foreach I will get the fields used. So the values received back are quite different.
-
Can one explain to me: semantics and syntax within your code? As for the code I posted above, I deleted the one with ->id (except for template) since it does not do anything extra. The way I think any page can be reached is like this. It's just an example based on a current page. In reality, any page could have a template, any page could be current, which would end up in different child/parent...: <h5>Example</h5> <ul> <li>parent page | template</li> <ul> <li>rootParent page</li> <ul> <li>siblings page</li> <li>$page (current) | template</li> <ul> <li>child page</li> <li>child page</li> </ul> </ul> </ul> </ul>
-
That was a enjoyable video! Things that do or don't make sence. Try to translate a dutch expression "jij bent in de boot genomen" and tell me what you think.
-
I see you are talking about the core code. Well, I just was testing with '->id', and although I can get the ID of the page I'm after (exept children = more then 1), it does not do anything else then that. Combining for instance '->id->name', or 'title' is out of the question. Why would we anyway? We can get it directly without the ->id ! Right now I work on my second sheet which are names. Yesterday, as I started with php. I thought let me see each vs foreach. Just for fun. The result is quite different. So the big question for me is: how are things indexed on a page level. I mean, on a empty page I guess you would have: ID | Name | Label | Title - as standard things. So directly accesible as in $page->title; Fields (custom) and their values are probably only retrievable by for example selector or get vs find.
-
Yes, that I know. But to just to keep it human language... Now I am using foundation (did it myself) to arrange my test content a little more nice. Made a test.php file with some basic code from the API, which I include in my site wide used template file (to test). Since I made pages on different levels, this simple code (which in your terms "explicitly ask for either of those") is included by default on any level of page I am in. Then it's easy to see what's going on. Mind you, my text are in my own words, so not to blame me please.... Here it is to test (ps. I made a tag called <code2> for another color to keep things clear): <?php // used to test on a per function based API // ?> <ul class="no-bullet"> <li>Code: <code>echo $page;</code> and <code2>echo $page->id;</code2></li> <li>Result: <code><?php echo $page;?></code> and <code2><?php echo $page->id;?></code2></li> <li>Both will give you the ID of the <em>current</em> viewed page.</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code>echo $page->rootParent;</code> and <code2>echo $page->rootParent->id;</code2></li> <li>Result: <code><?php echo $page->rootParent;?></code> and <code2><?php echo $page->rootParent->id;?></code2></li> <li>Both will give you the ID of the <em>root parent</em> page, from the current viewed page.</li> <li>This is <em>not</em> the top-level root from page tree!</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code>echo $page->parent;</code> and <code2>echo $page->parent_id;</code2></li> <li>Result: <code><?php echo $page->parent;?></code> and <code2><?php echo $page->parent_id;?></code2></li> <li>Both will give you the ID of the top level <em>parent</em> page (in the page tree).</li> <li>Mind the underscore in the code when using the last one!</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code>echo $page->child;</code> and <code2>echo $page->child->id;</code2></li> <li>Result: <code><?php echo $page->child;?></code> and <code2><?php echo $page->child->id;?></code2></li> <li>Both will give you the ID of the <em>first child</em> page, starting from the current viewed page.</li> <li>If nothing present, the first code is <code>empty (NONE)</code>, the second code is <code2>0 (NULL)</code2>.</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code>echo $page->children;</code></li> <li>Result: <code><?php echo $page->children;?></code></li> <li>This will give you the ID of the <em>children</em> pages.</li> <li>If nothing present, it will return <code>empty (NONE)</code>.</li> <li><span class="alert label">Don't excist</span> <code2>page->children->id</code2> and <code2>pages->children->id</code2>.</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code>echo $page->siblings;</code></li> <li>Result: <code><?php echo $page->siblings;?></code></li> <li>This will give you the ID of <em>same level</em> pages, called siblings.</li> <li>It will only return public listed pages.</li> <li><span class="alert label">Don't excist</span> <code2>page->siblings->id</code2> and <code2>pages->siblings->id</code2>.</li> </ul> <hr> <ul class="no-bullet"> <li>Code: <code2>echo $page->template->id;</code2> <li>Result: <code2><?php echo $page->template->id;?></code2></li> <li>This will give you the ID of the <em>template used</em> used for this page.</li> <li>With the <code>$page->template</code> you will only get template DB name: <code><?php echo $page->template;?></code></li> </ul> <hr>
-
Thanks! I just experiment with the API and started actually with a couple of rows: PHP in text format | PHP code executed | explenation And every line get a little more code inside, mixing, trying, and if it works, I save it. Now, I also realize: if I receive more then 1 result back (array) - of course I can GET it, but only the first result (if any), otherwise, I just have to itterate through them.
-
from: $page->parent; // what's my parent? to: $page->get(parent)->title; // retrieve the title of the parent page experimenting with: $page->get(parent)->fields; // take array from the template of the parents page itterating: $parentfields = $page->get(parent)->fields; foreach ($parentfields as $myfield) echo $myfield; // get field names from the template of the parent page and some: $page->get(modifiedUser)->name; // retrieve the name or like this: <a href='.$page->get(parent)->headline->url.'>'.$page->get(parent)->headline.'</a> // this way I can use a field value and link it to the page // ONLY THE URL IS WRONG... will check... // of course, it has to be : <a href='.$page->get(parent)->url.'>'.$page->get(parent)->headline.'</a> All fun so far! Type of code should be in a cheatsheet for newbies...
-
Thanks, but I have been through that 3 times. That's more then enough... Here's a nice thing I found out: <?php highlight_string('<?php phpinfo(); ?>') ;?> A inbuild php function to display code as text, just replace <?php phpinfo() ;?> with your code! Oh, wait. Of course you are right! It just returns the FIRST, probably based on date or ID. Thanks!
-
Well, today I started fresh, Only a dev branch. Nothing fancy, no changes, just made a couple of pages with childs and some content. Then I copied the part from API $page specifics and placed them in a table to include on my current page. That's exciting you might say! But it really give me some insight in what to expect using this $page variable. I then did the same for $pages, but in this case, only the $pages->find and $pages->get ones. I make this table as a find (more) vs get (one). But I had a suprise which I did not expect: $pages->get("selector, path or ID"); states that it can be a selector to. A selector from what I read can be template=basic-page, but this gave me the 404 page ID. So does it mean : a selector specified by path or id? Or : selector or path or ID?
-
yes, I believe I have to do it like that - for now (again!) I started from the DEV branch. Mainly because it's more clear looking at template files. I will just make my structure first...
-
Thank you guys, All above comments starting to make more sence to me now. But I must admit, I certainly need to look in php and learn more. I was really afraid I needed to go back to joomla or wordpress! My best bet is to simply forget about using a site profile (responsivenes > is so inviting) which often make it more difficult (functions > that I do not fully understand), or (wire > something) = huh?, and focus on the more simple ways to display content. So upon trying to understand the php, and also the API / cheatsheet, please share some php learning sites like the one linked above.
-
it's only good if you know how to use it. Like I said before: I am not good in php - so blaming me for asking I will take as policy I guess. I just keep trying to learn despite what some might think. But if I look at the page you described - which I did several times, I have no clue what to do with it: $a[$key] From description (in human language) I can see what it suppose to do. But since I started with PW, it was my understanding litlle knowledge of php was enough and I was thought $page->myfield->title So do I now have to make the $a into $page, and do I have to place 'myfield' in $key. Is my field a variable? Is $key the ID of something? How the &^* do I translate the first with the second?
-
The good read, was not so good... this: $a[$key] translates to me as "variable[iD]" - problem> I don't know ID upfront / how to turn $a into 'myselect' to use in array? 'fields' => array('summary','myselect'), - is not working for 'myselect' as value, only as ID. But why does it work for 'summary'? Are they not both strings of text? Will my only option then be to delete this function? Why does it say fields then? I am so confused (again) EDIT -------------------------- Somehow, you all pointed me in the right direction, since the first function takes on the second function I described I looked at this particulair part, and added ->title. Then when I use 'myselect' it returns my value. BUT NOW THE FIELD SUMMARY IS GONE!!! // render optional extra fields wrapped in named spans if(count($options['fields])) foreach($options['fields'] as $name) { $out .= "<span class='$name'>" . $item->get($name)->title . "</span> "; }
-
Foundation5 - I need to display additional fields after the body field which is declared as $body. But also in the list of children which is a function. Basically I am stuck again! - text input and area fields seems to be working fine, but selects are painfull. Maybe there is a function to grab selects and turn them into values to use in arrays? Anyway... In my basic-page.php is this code, which combines children list with $body: if($page->numChildren(true)) $body .= renderBodyNav($page->children); When I place my field after this code - it will be displayed under the children list (if it has any) and not directly after the $body variable. When I place my field in between - it will display, but only IF it HAS children. The function itself is this and displays the list with title and summary fields: function renderBodyNav(PageArray $items, array $options = array()) { $defaults = array( 'class' => 'body-nav side-nav', 'fields' => array('summary','myselect'), 'dividers' => true ); $options = array_merge($defaults, $options); return renderNav($items, $options) . renderPagination($items); } I can't simply put the single-select page field 'myselect' in the array, because it will just return ID. And the renderNav function (that is combined with the previous one) and displays as sidebar is this, where I also need additional fields: function renderNav(PageArray $items, array $options = array()) { if(!count($items)) return ''; $defaults = array( 'fields' => array(), // array of other fields you want to display (title is assumed) 'class' => '', // class for the <ul> 'active' => 'active', // class for active item 'dividers' => false, // add an <li class='divider'> between each item? 'tree' => false, // render tree to reach current $page? ); $options = array_merge($defaults, $options); $page = wire('page'); $out = "<ul class='$options[class]'>"; $divider = $options['dividers'] ? "<li class='divider'></li>" : ""; foreach($items as $item) { // if this item is the current page, give it an 'active' class $class = $item->id == $page->id ? " class='$options[active]'" : ""; // render linked item title $out .= "$divider<li$class><a href='$item->url'>$item->title</a> "; // render optional extra fields wrapped in named spans if(count($options['fields'])) foreach($options['fields'] as $name) { $out .= "<span class='$name'>" . $item->get($name) . "</span> "; } // optionally render a tree recursively to current $page if($options['tree']) { if($page->parents->has($item) || $item->id == $page->id) { $out .= renderNav($item->children("limit=50"), array( 'fields' => $options['fields'], 'tree' => true, )); } } $out .= "</li>"; }
-
foreach($page->pagefieldmulti as $selected) echo $selected->title; // worked excellent if($page->pagefieldmulti->has(1001)) echo "option page with ID 1001 is selected"; // worked not So I took the first code. foreach($job->check as $selected) { echo $selected->title; echo $selected->body; } So in pagefieldmulti I chose the parent page (for selectable childs) that will function as checkboxes. I then made a separate template for these child pages which have a title and body field. Now when I output these 'selected' pages, it will display those two fields as a title and description. Never once seen a cms that display multiple same fields (body in my case) in one article. Amazing what you can do with processwire - so many possibilities! And lucky there are many friendly people on this forum to help eachother. More will turn to PW for sure. Because these type of things would be weeks or maybe months on other cms.
-
Hey! thats very cool...
-
The page field I created, is of type checkboxes, and holds five pages. The field is called 'check'. Page names are one, two, three, four, five. It is a single page for now, only one checkbox can be chosen. Multi page would be great! But I need to display the chosen value and a description, for example : value 'one', description 'appel, peer, sinas'. edit - I will try with your code examples to find out by myself. Thanks for putting me on track. DO I GET MY TROFEE NOW $jobs = $pages->find('template=job, parent.template=jobs'); if (count($jobs)) { // only if we have jobs //$out = "<div>"; foreach ($jobs as $job) { $out = "<div class='item'>" . "<div><h3><a href='$job->url'>" . $job->title."</a></h3></div>" . "<div class='bold'>" . "<div>" . $job->contract->title . "</div>" . "<div>" . $job->branche->title . "</div>" . "<div>" . $job->education->title . "</div>" . "<div>" . // here I need to display the value chosen and optinal text for this value // ."</div>" . "</div>" . "<div" . trunc($job->body, 190) . "</div>" . "</div><hr>" ; echo $out; } }
-
hahaha! especially for me? wow! lol But listen, I did use the $page->fieldname->title on my template. So what exactly do you mean by 'there it is a object' since I tried that... I did not even know I could have a page then input field type checkbox - so thank you. But also this field get displayed with id's. As soon as I use in a foreach $jobs as $job ... $job->fieldname->title it's gone... I must be missing something EDIT ---- My bad, since it is now an array, I had to use implode!!!
-
I thought, after reading a article from ryan about asm select, maybe it IS easier to make use of a checkbox. Simply check the box - then display what you want. That way, I only need 6 checkboxes, against 40 pages. So instead of making a lot of pages for a certain multi select, I began to make my first checkbox field. As an example: Name: skill_one Label: skill one Description text: skiil one holds item1, item2, item,3 And thinking I could then display the name and description, I first started with echo $page->skill_one I ended up with either 0 or 1, which probably makes sense. But ->name or ->title or ->description does nothing. So how do I display the name, label or description. I can not find that anywhere? Sometimes, I wish there was also a cheatsheet for more fieldtypes with some examples. As a beginner, how was I to know a multi select is to be displayed with foreach or implode? The API simply stated $page->fieldname->title. Meanwhile I explode. lol
-
Thanks for that. Now I made mine with this implode: echo "<li>".$page->field->implode("</li><li>","title")."</li>"; Which will display the chosen values in a list.
-
Hello all, To enhance searching and find best answers it would be nice if : 1. on the main forum page 'recent topics' (on the right side); there would also be some kind of 'flag' if one of those topics is answered. Just like in the forum page with topics... I know it is not the main concern for PW, and it's just an idea.
-
I have gone through the API cheatsheet, and searched on the forum. But I could not find information about displaying values selected with multiselect field. Can anyone give me this? Furthermore, is it possible to limit number of selects for a multi select field? For example minimum 2 maximum 5.
-
Thanks Martijn, for pointing to $page: current page, and I did not know I had to use functionname in front. I simply had to use $child, since that was used in the foreach as a '$page e.g. current page'. After your previous replies, I have to ask, if this is the way to make a listing view page, or are there other more used techniques?
-
Here I am totally loosing you. it seems we made about the same time a reply. I did read it after, took the code, just not sure how to attach it to the $child->body But just to clarify, when I display this, I am talking about my page tree in back-end : root - listview // this is the page where I now try to retreive all items from under /all/ - all // or do I have to use this page to retrieve all items under it, is that the more logic way? - - item 1 - - item 2 on this listview (page) - i have this code: <?php foreach($pages->find("parent=/all/") as $child) { echo "<a href='{$child->url}'>{$child->title}</a>"; echo $shorty; // using soma's solution also displays nothing echo $child->branche->title; } ?>
-
Well, I have not met anyone using that long words. lol. But to explain: Look at the skyscrapers. The titel, body, and other fields make up the list of items. root - listview - all - - item 1 - - item 2 My currentpage (in this topic) is called - listview And I am trying to display the all/items on that listview page. Or do I have to use the parent page for that (am I doing it wrong?) And if limit characters would be the way, how you end it with a whole word 'what ...' instead of 'wh ...' ?