Skip to content

Instantly share code, notes, and snippets.

@iammilton82
Forked from raybrownco/wp-pods-vs-ee.php
Created November 25, 2015 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammilton82/d06fe4b4d7f760ce0e9b to your computer and use it in GitHub Desktop.
Save iammilton82/d06fe4b4d7f760ce0e9b to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment