Skip to content

Instantly share code, notes, and snippets.

@jasperf
Created February 15, 2017 08:14
Show Gist options
  • Save jasperf/9fc605a726349b27a9bebf9bb999be94 to your computer and use it in GitHub Desktop.
Save jasperf/9fc605a726349b27a9bebf9bb999be94 to your computer and use it in GitHub Desktop.
featured product slider function
function featured_products_slider()
{
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'post_status' => 'publish'
);
$featured = get_posts($args);
foreach ($featured as $post) {
$thumb_id = get_post_thumbnail_id($post, 'featured');
$imageUrl = wp_get_attachment_url($thumb_id);
$permaLink= get_permalink($post);
$authorID = $post->post_author;
$productIntro = get_the_excerpt( $post );
$title = $post->post_title;
$date = get_the_date('M j, Y', $post->ID);
?>
<li>
<div class="featured-post-slide">
<div class="post-background" style="background-image:url('<?=$imageUrl;?>');"></div>
<div class="shadow"></div>
<div class="post-content">
<h1 class="slide-title">
<a href="<?=$permaLink?>"><?=$title?></a></h1>
<p>
<?= $productIntro ?>
</p>
<a href="<?=$permaLink?>" title="<?=$title?>" class="button stroke more-link">Shop now</a>
</div>
</div>
</li>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment