WordPress.org

Ready to get started?Download WordPress

Forums

adding adsense after 1st post on frontpage (8 posts)

  1. mm1985
    Member
    Posted 1 year ago #

    I am trying for some time to add a adsense block after the 1st post on the frontpage.

    Now I have looked on the internet how to do it and they didnt work.

    I also tried to use plug in such as ads easy, ad injection and frontpage banner.

    So far non of them works.

    I am using the NewsMagazine Theme and my page.php looks as follow:

    <?php global $theme; get_header(); ?>
    
        <div id="main">
    
            <?php $theme->hook('main_before'); ?>
    
            <div id="content">
    
                <?php $theme->hook('content_before'); ?>
    
         <script type="text/javascript"><!--
    google_ad_client = "**************";
    /* _ */
    google_ad_slot = "********";
    google_ad_width = 468;
    google_ad_height = 15;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
                <?php
                    if (have_posts()) : while (have_posts()) : the_post();
    <?php $count = 1; ?>
                        /**
                         * Find the post formatting for the pages in the post-page.php file
                         */
                        get_template_part('post', 'page');
    
    <?php if ($count == 1) : ?>
    <script type="text/javascript"><!--
    google_ad_client = " ";
    /* textblok */
    google_ad_slot = " ";
    google_ad_width = 336;
    google_ad_height = 280;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php endif; $count++; ?>
                        if(comments_open( get_the_ID() ))  {
                            comments_template('', true);
                        }
                    endwhile;
    
                    else :
                        get_template_part('post', 'noresults');
                    endif;
                ?>
    
                <?php $theme->hook('content_after'); ?>
    
            </div><!-- #content -->
    
            <?php get_sidebars(); ?>
    
            <?php $theme->hook('main_after'); ?>
    
        </div><!-- #main -->
    
    <?php get_footer(); ?>

    I hope someone can tell me how to add the adsense after the 1st post.

    ps. the first adsense code is for a horizontal banner above the 1st post which is working.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    after the 1st post on the frontpage

    are you using a static front page?

    what is the code producing at the moment?
    can you post a link?

    possibly consider using the conditional tag:

    is_front_page()

    to change this line:

    <?php if ($count == 1) : ?>

    into:

    <?php if ($count == 1 && is_front_page() ) : ?>
  3. mm1985
    Member
    Posted 1 year ago #

    my page is dynamic. http://www.reportson.com

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    for a dynamic front page, i.e. a front page with all the posts, you might need to edit index.php and use:

    <?php if ($count == 1 && is_home() ) : ?>

    http://codex.wordpress.org/Template_Hierarchy
    http://codex.wordpress.org/Conditional_Tags

  5. mm1985
    Member
    Posted 1 year ago #

    I added <?php if ($count == 1 && is_home() ) : ?> but nothing changed in frontpage.

  6. dwnmedia sarl
    Member
    Posted 1 year ago #

    have you edit index.php file instead of page.php?

  7. mm1985
    Member
    Posted 1 year ago #

    No I edited page.php

  8. dwnmedia sarl
    Member
    Posted 1 year ago #

    if it is a DYNAMIC homepage edit INDEX.PHP as @alchymyth have told you

Topic Closed

This topic has been closed to new replies.

About this Topic