Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This file is a comparison between WordPress/Pods and ExpressionEngine. It shows the syntax required to display a list of three featured books on a site's homepage.
<!-- Featuring three books on a site's homepage -->
<!-- The Pods/WordPress way -->
<ul id="featured-books">
<?php
$book = new Pod('book');
$params = array(
'where'=>'t.show_on_homepage = 1',
'limit'=>3,
'orderby'=>'t.release_date DESC'
);
$book->findRecords($params);
if($book->getTotalRows() > 0)
{
while($book->fetchRecord()) :
$title = $book->get_field('title');
$subtitle = $book->get_field('sub_title');
$cover = $book->get_field('cover');
$description = $book->get_field('description');
$buyingOptions = $book->get_field('buying_options');
$buyingOptionLinks = array();
if($buyingOptions)
{
$buyingOptionsArray = explode("\n", $buyingOptions);
foreach($buyingOptionsArray as $buyingOption)
{
$linkArray = explode('|', $buyingOption);
$link = '<li class="'. trim('_'.$linkArray[0]) .' icon replace"><a href="'. trim($linkArray[1]) .'" target="_blank"><span>'. trim($linkArray[0]) .'</span></a></li>';
array_push($buyingOptionLinks, $link);
}
}
?>
<li class="book">
<?php if($cover) { ?>
<h1><?=$title;?></h1>
<h2><?=$subtitle;?></h2>
<div class="cover">
<?php
if($buyingOptionsArray) {
$linkArray = explode('|', $buyingOptionsArray[0]);
?>
<a href="<?php echo $linkArray[1]; ?>" target="_blank">
<img src="<?php echo $cover[0]['guid']; ?>" alt="<?=$title;?>" /><br/>
<span class="purchase-text">Purchase Book</span>
</a>
<?php } else { ?>
<img src="<?php echo $cover[0]['guid']; ?>" alt="<?=$title;?>" />
<?php } ?>
</div>
<?php } ?>
<div class="description"><?=$description;?></div>
</li>
<?php
endwhile;
}
?>
</ul>
<!-- The ExpressionEngine way -->
<ul id="featured-books">
{exp:channel:entries channel="books" search:show_on_homepage="=yes" limit="3" orderby="release_date" sort="desc"}
<li class="book">
<h1>{title}</h1>
<h2>{subtitle}</h2>
<div class="cover">
{if buying_options}
{buying_options limit="1"}
<a href="{link}" target="_blank">
<img src="{cover_thumbnail}" alt="{title}" /><br/>
<span class="purchase-text">Purchase Book</span>
</a>
{/buying-options}
{if:else}
<img src="{cover_thumbnail}" alt="{title}" />
{/if}
</div>
<div class="description">{description}</div>
</li>
{/exp:channel:entries}
</ul>
@sc0ttkclark
Copy link

sc0ttkclark commented Jan 24, 2013

Also, to revisit this, Pods 2.x syntax is cleaner, more efficient, and less coding work than Pods 1.x as shown above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment