Skip to content

Instantly share code, notes, and snippets.

@mikeott
Last active September 18, 2023 05:48
Show Gist options
  • Save mikeott/1e5f218b66c28c2b6bb469e6da05d6d3 to your computer and use it in GitHub Desktop.
Save mikeott/1e5f218b66c28c2b6bb469e6da05d6d3 to your computer and use it in GitHub Desktop.
WordPress add paramater to function for CPT
<?php
/*
Funds list
Usage:
funds_list(false); // Include the images
or
funds_list(); // DOon't include the images
*/
function funds_list($output_images = true) {
echo '<ul class="funds-list no-margin no-padding">';
$args = array(
'post_type' => 'fund',
'posts_per_page' => -1
);
$query = new WP_Query($args);
while ($query->have_posts()) : $query->the_post();
$cover_image = get_template_directory_uri() . '/images/project-hero.webp';
if ($output_images && $cover_image) {
$cover_image = get_field('cover_image');
}
?>
<li>
<a href="<?php echo get_the_permalink(); ?>">
<span><?php echo the_title(); ?></span>
<?php if ($output_images) : ?>
<img src="<?php echo $cover_image; ?>" alt="<?php echo get_the_title(); ?>" />
<?php endif; ?>
</a>
</li>
<?php endwhile;
wp_reset_postdata();
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment