Last active
August 29, 2015 14:11
-
-
Save michaelbrazell/93c4302ac51722d0e5fe to your computer and use it in GitHub Desktop.
Usings Pods to loop through a number of posts outside the loop (in this case a custom pod called "links" ) and displaying them by category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Declare paremeters of Pods | |
// Limiting by 4, and looping through the category slug called "for-parents" | |
$params = array( | |
'limit' => 4, | |
'where' => "category.slug = 'for-parents'" | |
); | |
// Create a variable called $links and assign that my pod called "link" pulling in the parameters from above | |
$links = pods('link', $params ); | |
// If there are more than 0 links, let's display them! | |
if ( $links->total() > 0) { | |
while ( $links->fetch() ) { | |
// Creating some variables from these fields I've defined | |
$text = $links->field('text'); | |
$url = $links->field('url'); | |
$target = $links->field('target'); | |
// In this case, I only want to write the $target variable if it has content. This is for _blank, _self, etc. | |
if ( $target != '') { | |
echo "<a href='$url' target='$target'>$text</a>"; | |
} else { | |
echo "<a href='$url'>$text</a>"; | |
} | |
} // while loop | |
} // if conditional | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment