[resolved] Modifying Twenty Ten (6 posts)

  1. sueme
    Posted 6 years ago #

    I'm using WP 3.0 and the twenty Ten child theme and I want to know how to code a Google Ad into the middle of a page without using a plugin.

    I've played about a bit on a test site on my PC and know how to get an ad to display at the top or the bottom of the page, but really I'd like one somewhere in the middle instead. I've seen plugins that do this, but is it possible without?

    Below is the main part of the page.php

    Can anyone help me please?

    <h1 class="entry-title"><?php the_title(); ?></h1>
    <?php } ?>				
    <div class="entry-content">
    // I know I can place google ad code here to display at the top		
    <?php the_content(); ?>						
    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>						
    // I know I can place google ad code here to display at the bottom					
    </div><!-- .entry-content -->							
    </div><!-- #post-## -->
  2. webjunk
    Posted 6 years ago #

    BEFORE - Will place before content
    <?php the_content(); ?>
    AFTER - Will place After content

    To be in the middle of the content you will need to eithr place it in the (html) page/post itself or get much more in depth in the code.

  3. sueme
    Posted 6 years ago #

    Thanks Webjunk,

    I don't mind getting more in depth with the code (Just bought, but not yet read, CSS The Missing Manual).

    Just need pointing in the right direction please.

  4. Rev. Voodoo
    Posted 6 years ago #

    <?php $story = get_the_content();
    $story = explode('<span id="more',$story);
    $first_part_of_story = $story[0];
    $second_part_of_story = $story[1];
    $first_part_of_story = apply_filters('the_content', $first_part_of_story);
    echo $first_part_of_story;
    if ($second_part_of_story) { /*here any code for advertising */ ;
    $second_part_of_story = explode('</span>',$second_part_of_story);
    $second_part_of_story = apply_filters('the_content', $second_part_of_story[1]);
    echo $second_part_of_story;  ?>

    I believe this is from @alchymyth

    replaces <?php the_content(); ?>

    If I'm not mistaken...in your page, you would use the <!--more--> to designate where the story gets broken up, and where the ad goes

  5. sueme
    Posted 6 years ago #


    Works a treat.

    Thank You Very, Very much.


  6. Michael
    Forum Moderator
    Posted 6 years ago #

    another, more independant method is to create a shortcode for ads:

    in functions.php of the theme, add:

    // [adsense]
    function add_adsense($atts) {
    return '<span class="adsense">
    <script type="text/javascript"><!--
    google_ad_client = "pub-0123412341234123";
    /* your google ads */
    google_ad_slot = "1234512345";
    google_ad_width = 468;
    google_ad_height = 60;
    <script type="text/javascript"
    add_shortcode('adsense', 'add_adsense');

    substitute your own google code.
    the span with the class .adsense is optional to style the ads (for instance use float:left; with some margins to let the text float around the ads);
    place them whereever you want in a post or page by typing [adsense] into the text.

Topic Closed

This topic has been closed to new replies.

About this Topic