gfdesign Posted May 31, 2013 Posted May 31, 2013 Hi everyone.I'm from Argentina so my appologies for my English (I'm begginer student). As I've read in other post, I also came from Textpattern world. Other fantastic CMS that gave me many satisfactions. I'm looking forward for the next version TXP5, meanwhile I'd like try on PW because many interesting things have catched my attention. I'm graphic designer with some HTML / CSS knowledge but almost or nothing of PHP. I think I've understood how PS works, but I'm stucked in something that should be very simple. So here there is my first doubt.I want to put a list of pages are using a specify template with my own markup. I guess I should use a similar code like this: $skyscrapers = $pages->find("template=skyscraper"); foreach($skyscrapers as $s) echo "<li><a href='{$s->url}'>{$s->title}</a></li>"; But, I can't understand what is $s for or how I could limit the number of pages (amongst other things) I want to show. So, I'll be grateful if someone can clear me up. I have a lot of questions but I'll try to find out by myself, if not, probably I'll go back for here On other hand, I haven't seen a forum in Spanish, so I'd like users who speak it create one. Also, I would want to offer my help for translating PW to my language and this way Spanish community goes raising such as it happens on TXP forums.Best regards and thanks in advance.Fernando
arjen Posted May 31, 2013 Posted May 31, 2013 $s is like one item which belongs to the group $skyscrapers. I prefer to name them $skyscraper so you have: foreach($skyscrapers as $skyscraper) { echo "<li><a href='{$skyscraper->url}'>{$skyscraper->title}</a></li>"; } See more about a foreach in the manual. If you want to limit the number of results you can do this: $skyscrapers = $pages->find("template=skyscraper, limit=10"); There are some great tutorials in this forum or on the wiki. I would recommend to do them all. I'm coming from TXP too and and while I still like it very much, ProcessWire is second to none when it comes to structuring data. 2
kongondo Posted May 31, 2013 Posted May 31, 2013 Fernando, Welcome to PW. In other words, that $s is a temporary variable created to hold information about all the pages found by this $pages->find("template=skyscraper"). In order to get the most out of PW, I recommend that you first learn some basic PHP. See this thread for suggestions about good PHP learning resources. Cheers 1
gfdesign Posted May 31, 2013 Author Posted May 31, 2013 Many thanks guys for reply so soon and the welcome. Yes, I agree what Arjen said. ...ProcessWire is second to none when it comes to structuring data. That was one of thing that catched my attention because to me would be much easier to explain to my clients how is organized his site and so to have a general vision about the contents. And let's not even talk about the content custom types and drag and drop features. I love them! I like TXP because never was necessary to me learn PHP, but seeing PW potential, I'll try to study it, so thanks for the suggestions.Very soon, I'll go back with new questions Best regards
dragan Posted May 31, 2013 Posted May 31, 2013 There is lots of reading material: http://processwire.com/api/ http://processwire.com/videos/ http://processwire.com/talk/forum/13-tutorials/
diogo Posted May 31, 2013 Posted May 31, 2013 and this http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/ edit: Fernando, there is already a spanish translation for the admin http://processwire.com/talk/topic/1003-spanish-es-es/
gfdesign Posted June 2, 2013 Author Posted June 2, 2013 Thanks Diogo. It seems very interested.Regards
renobird Posted June 2, 2013 Posted June 2, 2013 gfdesign, I spent years working with TXP and still maintain a small handful of TXP sites for existing clients. You really don't need to know very much PHP to build sites with ProcessWire. Sure, if you want to build complex things, then you might need a little deeper understanding, but for most sites you don't need more than the basics. Using the example you posted above, let's compare (as closely as possible), ProcessWire to TXP methods. ProcessWire // get pages with the template "skyscraper" $skyscrapers = $pages->find("template=skyscraper"); // for each "skyscraper" display the following foreach($skyscrapers as $s){ echo "<li><a href='{$s->url}'>{$s->title}</a></li>"; } Texpattern In your page: // Get all articles with the category "skyscraper", use form "list" to display them. <txp:article_custom category="skyscraper" form="list" /> In the form "list": // for each article display the following <li><txp:permlink><txp:title /></txp:permlink></li> If you take the TXP tags out of it, there really isn't much difference. When you call a form in TXP, you are basically creating a foreach(). For creating most sites with PW you really don't need to know all that much PHP. Brush up on the basics and dive in. Ask lots of questions, there are nice folks here who are always willing to help. Oh yeah... Welcome. 3
diogo Posted June 2, 2013 Posted June 2, 2013 In this case it makes sense to show an alternative way of doing what Reno showed. Just to make it a bit closer to the TXP example: <ul> <?php foreach ($pages->find("template=skyscraper") as $s): ?> <li><a href='<?=$s->url?>'><?=$s->title?></a></li> <?php endforeach; ?> </ul> 2
renobird Posted June 2, 2013 Posted June 2, 2013 Diogo, that is true, and I probably should have show it as a container tag: <ul> <txp:article_custom category="skyscraper"> <li><txp:permlink><txp:title /></txp:permlink></li> </txp:article_custom> </ul> Either way, just as simple with ProcessWire. 1
gfdesign Posted June 2, 2013 Author Posted June 2, 2013 Thanks Guys, for so many examples using TXP as reference. All of you have been a great help so I'll put on practice your advices. Surely, I'll go back for more questions about lists of pages or other things. I hope to be helpful to you as well.Best regards 2
gfdesign Posted June 9, 2013 Author Posted June 9, 2013 Dears, I've followed yours examples but I they don't work when I want to sort such as I have in my control Panel. Pages always display sorted such as I've created them and not as I sort them using drag and drop feature. I'm using next code to show a list of pages. <?php $trabajos = $pages->find("template=trabajo"); foreach($trabajos as $trabajo){ echo "<div class='module01 mosaic-block bar'>"; echo "<a href='{$trabajo->url}' class='mosaic-overlay'>"; echo "<div class='details'>"; echo "<h4>{$trabajo->title}</h4>"; echo "<p>{$trabajo->description}</p>"; echo "</div>"; echo "</a>"; echo "<div class='mosaic-backdrop'><img src='{$trabajo->imagen_principal->url}' alt='' /></div>"; echo "</div><!--/module01 -->"; } ?> Do you have any idea what could be the problem in my code why they don't sort as I see in my Administrator's screen? Worth mentioning, I've selected "Manual drag'n drop" in the 'Children are sorted by' field of theirs parent page.Best regards Fernando
slkwrm Posted June 9, 2013 Posted June 9, 2013 Try to add sort option to your selector (sort=sort or sort=-sort for reverse order): $pages->find("template=trabajo, sort=-sort"); 1
diogo Posted June 9, 2013 Posted June 9, 2013 ... and if it still doesn't work, call as children of their parent (i'm assuming they have the same parent) $trabajos = $pages->get('trabajos-parent')->children("template=trabajo, sort=sort"); 1
gfdesign Posted June 9, 2013 Author Posted June 9, 2013 Thanks guys!. Slkwrm's suggestion works. Diogo what you propose didn't work me. Probably I'm doing some mistake due to my scarce knowledge of PHP and PW as well.Thanks again
diogo Posted June 9, 2013 Posted June 9, 2013 My code is assuming some things and has to be adapted to your situation. How did you use it exactly?
gfdesign Posted June 9, 2013 Author Posted June 9, 2013 I'm working on a portfolio site. My structure is the next: Home Trabajos (I've put the code in this page/template) Trabajo 1 Trabajo 2 Trabajo 3... Trabajo N StoreContacto With your snippet, the code looks like so: <?php $trabajos = $pages->get('trabajos-parent')->children("template=trabajo, sort=sort"); foreach($trabajos as $trabajo){ echo "<div class='module01 mosaic-block bar'>"; echo "<a href='{$trabajo->url}' class='mosaic-overlay'>"; echo "<div class='details'>"; echo "<h4>{$trabajo->title}</h4>"; echo "<p>{$trabajo->description}</p>"; echo "</div>"; echo "</a>"; echo "<div class='mosaic-backdrop'><img src='{$trabajo->imagen_principal->url}' alt='' /></div>"; echo "</div><!--/module01 -->"; } ?> Each page has your own template, except all "trabajo" pages that share same template "trabajo".
slkwrm Posted June 9, 2013 Posted June 9, 2013 You should substitute trabajos-parent with the selector to chose the page that is a parent of your Trabaho 1...n pages. In your case you don't even need to use a selector, it should be: $trabajos = $page->children("template=trabajo, sort=sort"); and if you only have pages with this 'trabajo' template under your trabahos page, you don't need to spacify it in your selector, so it shrinks to: $trabajos = $page->children("sort=sort"); 1
gfdesign Posted June 10, 2013 Author Posted June 10, 2013 Yes, you're right. Both codes work as I want. Thanks for the explanation. Fernando
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now