Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Last active May 31, 2022 11:41
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 pandanote-info/eaadbac18978dd23aa1bba0b7626c90d to your computer and use it in GitHub Desktop.
Save pandanote-info/eaadbac18978dd23aa1bba0b7626c90d to your computer and use it in GitHub Desktop.
YARPPプラグインによる関連記事へのリンクのリストにAdSenseのインフィード広告を紛れ込ませるためのコード。
<h2>Related Posts / 関連ページ</h2>
<?php if(have_posts()):?>
<div class="related-post-list">
<?php $adpos = 0; ?>
<?php while(have_posts()) : the_post(); ?>
<?php if ($adpos == 1): ?>
<!-- Insert your infeed ad -->
<?php endif; ?>
<a href="<?php the_permalink() ?>"
title="<?php the_title_attribute(); ?>"
rel="bookmark"
class="related-post">
<?php if(has_post_thumbnail()) : ?>
<?php the_post_thumbnail(array(125, 125)); ?>
<?php else : ?>
<img src="<?php echo plugins_url() . '/' . 'yet-another-related-posts-plugin/images/default.png' ?>"
alt="no thumbnail"
title="no thumbnail"/>
<?php endif; ?>
<?php the_title(); ?>
</a>
<?php $adpos++; ?>
<?php endwhile; ?>
</div>
<?php else : ?>
<p>関連するページはありません。</p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment