###前提・実現したいこと
wordpressで作成したウェブサイトに、googleアドセンスのインフィード広告を設置したいのですが、
できなくて困っています。
###発生している問題・エラーメッセージ
ネットで検索した情報を元に、子テーマのhome.phpにコードを追加するなど色々試しましたが、 レイアウトが崩れてしまったり、何も表示されなくなったりしてうまくいきません。
###該当のソースコード
こちらが子テーマのhome.phpです。 インフィード広告を設置するコードを入力するために、 親テーマの内容をコピーしたものです。 <?php /** * The template for displaying the blog index (latest posts) * * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package Tortuga */ get_header(); // Get Theme Options from Database. $theme_options = tortuga_theme_options(); // Display Slider. if ( true === $theme_options['slider_blog'] ) : get_template_part( 'template-parts/post-slider' ); endif; ?> <section id="primary" class="content-archive content-area"> <main id="main" class="site-main" role="main"> <?php // Display Magazine Homepage Widgets. tortuga_magazine_widgets(); if ( have_posts() ) : // Display Blog Title. tortuga_blog_title(); ?> <div id="post-wrapper" class="post-wrapper clearfix"> <?php while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content' ); endwhile; ?> </div> <?php tortuga_pagination(); else : get_template_part( 'template-parts/content', 'none' ); endif; ?> </main><!-- #main --> </section><!-- #primary --> <?php // Do not display Sidebar on Three Column Post Layout. if ( 'three-columns' !== $theme_options['post_layout'] ) : get_sidebar(); endif; ?> <?php get_footer(); ?> ```下記のコードなどを追加して試しましたが、うまくいきませんでした。
$count = 1;
if($count==4){
[ここにインフィード広告のコードを添付]
}
$count = $count + 1;
または、
<?php $ads_infeed = '4'; // $ads_infeed_count = '1'; ?>``` <?php if($ads_infeed_count == $ads_infeed){ ?> <!-- ここにインフィード広告のコードを添付 --> <?php } $ads_infeed_count++; ?>または、
<?php if (have_posts()) : while (have_posts()) : the_post(); $count++; ?> <?php if ($count == 4): ?>ここにインフィード広告のコードを添付
<?php elseif ($count == 8): ?>ここにインフィード広告のコードを添付
<?php endif; ?>などです。
私は素人のため説明に至らない点があると思いますが、よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。