Jump to content

renobird

PW-Moderators
  • Posts

    1,699
  • Joined

  • Last visited

  • Days Won

    14

Everything posted by renobird

  1. How can I detect (and add additional markup) to the first/last iteration using the API? Here's an example: $profiles = $pages->get("/meet-us/executive-profiles")->children("limit=5"); foreach ($profiles as $profile) echo "<h2>{$profile->job_title}</h2>". "{$profile->biography}"; With raw PHP I would add a counter to the foreach: $i = 0; $length = count($profiles); foreach ($profiles as $profile) { if ($i == 0) { // first } else if ($i == $length - 1) { // last } $i++; } I'm sure there's a more elegant solution using the API. I think I need to use $a->$key, but I'm not quite sure how to put it together. Any guidance would be much appreciated.
  2. Hey Steve, Long time eh? I'm glad to see you here as well. I still keep tabs on the TXP forums, but I tend to build the same kinds of sites with TXP lately, as a result I don't have a lot to ask about or contribute. I have a fairly involved design/build coming up at my new job — and ProcessWire fits the bill perfectly. I think you'll be seeing a lot of me around here.
  3. Wow. Thanks everyone! There's a lot to wrap my head around in the post that Jasper and Marc linked. I can certainly see the benefit for larger projects though. I'll spent some time digesting those methods tonight. Ryan, creating a tools.inc to store functions is great! I'm a hack at PHP (at best), so some of my learning curve is more than just the API.
  4. Hello All, I'm just starting my first PW build (and I love it so far.) I'm looking for some ideas on how others create reusable content, like sidebars or other content that may get displayed in any number of templates. I'm a long time Textpattern user, and reusable content like this is handled fairly easily. It appears to be just a simple with PW, but I'm still getting my head around the API. I thought I'd show my current thinking, and ask for any feedback or suggestion on alternate methods. Basic example of reusable content: On a home page I want to display the latest news item, and on another page I want to display the latest 3. My current method is to call a template named news_posts.inc like so: <?php $news = $pages->get("/news/")->children("limit=1"); include("./news_posts.inc"); ?> To show more posts on another page, I just increase the limit. For the sake of this example, let's say news_posts.inc just shows the title of each post: <?php foreach ($news as $item) echo "<p>{$item->title}</p>"; ?> This works fine, and is pretty straight-forward, I'm just curious if there are other methods or if I'm on the right path.
×
×
  • Create New...