Jump to content

My first doubt using PW


gfdesign
 Share

Recommended Posts

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

Link to comment
Share on other sites

$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.

  • Like 2
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

  • Like 3
Link to comment
Share on other sites

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>
  • Like 2
Link to comment
Share on other sites

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.

:)

  • Like 1
Link to comment
Share on other sites

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

  • Like 2
Link to comment
Share on other sites

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

Link to comment
Share on other sites

... 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");
  • Like 1
Link to comment
Share on other sites

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

Store
Contacto

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".

Link to comment
Share on other sites

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");
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...