Name Mon Lu

Love jQuery/CSS

Blog about Webdev

Twitter supawaza

RSS Twitter Flickr

What I am up to:


I’ve been very silent on Face­book, Twit­ter, and this blog lately. That because I can’t con­stantly access Twit­ter any­more from work, they blocked me… so no more use­ful stuff to tweet and brag about excepted one thing: Pods CMS. Pods CMS is a Word­Press plu­gin that pretty much turn your blog into a CMS. You can build a Wiki, Glos­sary, Recipes, Hotel list­ing etc… the pos­si­bil­i­ties are end­less. Although, you will need to know at least some PHP to make this thing tuned to the way you want it to be. I have been play­ing with it in the past 2 weeks, I have to say I am very impress of how this plu­gin works. So I did a test on one of my hob­bies: Kendo. I’ve always wanted to col­lect data on Kendo Dojo, how many prac­ti­tion­ers, and Kendo tour­na­ment results in the U.S. I was able to cre­ate this very com­plex data­base that it can be listed by Fed­er­a­tions, State, Coun­try, Dojo, and down to the indi­vid­ual Kendo-ist data. The awe­some thing is? Each list­ing can be linked to one another. For exam­ple, if you view­ing by Fed­er­a­tions, you can list all the Dojo in that fed­er­a­tion, and with links to each Dojo AND the state. You can add BUILT-IN fil­ters and search on top! The back­end is all done for you, all you have to do is to make things pretty. Ain’t that grant?

The prob­lem of this awe­some plu­gin that it is quite new, the doc­u­men­ta­tions, tuto­ri­als, and resources are quite lim­ited. But the devel­op­ers are extremely help­ful on their own forum – so you’ll have to do a lot of dig­ging to find the answers you need… in which I did. I also found the tuto­ri­als were kind of half way done, they stopped at dis­play­ing the data, but not show­ing how to write sim­ple Dis­play Helper and Input Helper. So I’m going to jog that down here.

If you have not gone through the doc­u­men­ta­tions and have some basic data to play with, you should get going (think­ing putting one sim­ple guide of how to put all the pods together later).

Dis­claimer:

The fol­low­ing helpers are very basic ones that I found myself used them a lot and repeat­edly, so hope­fully these will be use­ful for some­one else also.  On a side note that I am NOT a hard­core PHP coder, I under­stood enough basic PHP codes to cus­tomize them. If you know a bet­ter way, feel free.

So let’s get rolling…

Soft­ware Note: Pods CMS 1.7.3 / WP 2.8.4

Doc­u­men­ta­tion: http://pods.uproot.us/codex/helpers

Dis­play Helpers: Dis­play Helpers are the codes that help to dis­play your results in a nicer, cus­tomized look.  For exam­ple, say that you want to show all of your ingre­di­ents in a recipe, by default, they’ll be list as such: “Ingre­di­ent 1Ingredient 2″ – it is hard to read.  So you can write a Dis­play Helper to show them as “Ingre­di­ent 1, Ingre­di­ent 2″.  Got it?

By default, the Dis­play Helper passes $value as an array for you to manip­u­late as such: $value[0][’column_name’].

Adding a Dis­play Helper

Adding a new Dis­play Helper is very sim­ple, see below:

Pods CMS - Add new Display Helper

Pods CMS – Add new Dis­play Helper

List Sin­gle Result ONLY (No Link)

Add a new Dis­play Helper and name this one some­thing like “print_r”:

<?php print_r($value[0]['name']); ?>

I have these two generic Dis­play Helpers dis­play­ing a sin­gle result only.  By default, if you hav­ing some­thing like {@column_name}, it will show column’s name and it is linked to a its own detailed page (if it is bi-directional), some­thing like (http://domain.com/your_pod/column_name/1).  Where the very last part is actu­ally the row ID.  So what if you want to dis­play your data with a cus­tom permalink/slug?  Such as: (http://domain.com/your_pod/slug_name)  This helper will come in handy in your Pod Tem­plates page:

<a href="/pod_name/{@slug}">{@column_name,print_r}</a>

You prob­a­bly noticed that I put the helpers right next to the Magic Tags instead of adding the Dis­play Helpers like this:

Display Helper

Dis­play Helper

It’s a mat­ter of per­sonal pref­er­ence really. If you want, you can add the helper inside the admin inter­face. If you’d rather add the Dis­play Helper through the admin inter­face, you don’t need to add “print_r” inside {@print_r}.

Dis­play­ing Arrays

The fol­low­ing will dis­play “Ingre­di­ent 1, Ingre­di­ent 2, Ingre­di­ent 3″ instead of “Ingre­di­ent 1Ingredient 2Ingredient 3″ with links or no link to your liking:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$pod = pods_url_variable('first');
 
if (is_array($value) && 0 < count($value))
{
    foreach ($value as $val)
    {
        $output[] = "<a href='/".$pod."/".$val['slug']."' />".$val['name']."</a>";
    }
echo implode(', ', $output);
} else {
   echo "No record found";
}
?>

If you just want to dis­play the results with­out the links, sim­ply remove the “href” on line 8.

Note: This helper will only link to cur­rent pod, what I mean: “/pod1/slugname”, but not able to link “/pod2/slugname”. The rea­son is that this script will only grab the pod’s name which is “/pod1″ and add itself to the “a href…”. If you want to link to a dif­fer­ent pod, you’ll just have to add a new helper with a minor change of instead of ‘$pod’ (line 8 ) where the “a href…” is to your actual pod’s name, make sense?

Well, that’s it for now… next up, Input Helper.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • email
  • Ping.fm
  • Reddit
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

No related posts.

This entry was posted on Thursday, September 24th, 2009 at 12:31 PM and is filed under Pods CMS, Web Dev. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

No Responses to “Pods CMS — Display Helpers”