Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Shelob9/75d074af88b62eeabf76 to your computer and use it in GitHub Desktop.
Save Shelob9/75d074af88b62eeabf76 to your computer and use it in GitHub Desktop.
<?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
?>
@michaelbrazell
Copy link

This is great, thanks!

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