Forked from michaelbrazell/Pods_Loop-through-post-type-by-category
Last active
August 29, 2015 14:11
-
-
Save Shelob9/75d074af88b62eeabf76 to your computer and use it in GitHub Desktop.
This file contains 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='". esc_url( $url ) ."' target='". esc_attr( $target ) ."'>$text</a>"; | |
} else { | |
echo "<a href='". esc_url( $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
This is great, thanks!