Skip to content

Instantly share code, notes, and snippets.

@metamn
Created February 5, 2019 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metamn/b052d61cc36ae86a4c0de4e7fed38638 to your computer and use it in GitHub Desktop.
Save metamn/b052d61cc36ae86a4c0de4e7fed38638 to your computer and use it in GitHub Desktop.
A WordPress post list with ad
<?php
/**
* Displays a list of posts with an ad
*
* @package Pointhacks
*/
$post_list_title = get_query_var( 'post-list-title', 'Post list' );
$post_list_klass = get_query_var( 'post-list-klass', 'post-list--default' );
$post_list_posts = get_query_var( 'post-list-posts', null );
$post_list_post_format = get_query_var( 'post-list-post-format', '' );
$post_list_ad = get_query_var( 'post-list-ad', null );
if ( empty( $post_list_posts ) ) {
return;
}
?>
<section class="post-list <?php echo esc_attr( $post_list_klass ); ?>">
<h3 class="post-list-title">
<span class="text"><?php echo esc_attr( $post_list_title ); ?></span>
</h3>
<div class="post-list-items">
<?php
foreach ( $post_list_posts as $index => $post ) {
if ( ! empty( $post_list_ad ) ) {
if ( $index === $post_list_ad['insert_at'] ) {
echo $post_list_ad['content'];
}
}
get_template_part( 'template-parts/post/post', $post_list_post_format );
}
?>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment