Month: May 2010

  • HOW TO: Adsense Section Targeting In Thesis

    Adsense section targeting should be adopted by any publisher serious about earning bucks from the Google Adsense advertisements program on their Thesis site. Targeting basically means telling Adsense which sections of your content should be considered for displaying contextual ads. For example, on a site like Niponwave where I display the OS of the users leaving comments here and a lot of people use Windows, if I were running Adsense, the word ‘Windows’ would have been picked up and many of my visitors would see advertisements related to the Microsoft OS. Get the drift? But if you want to show only relevant and contextual ads to your visitors then adsense section targeting is what you should be after. In fact, this is a recommended practice. Without further ado, let me type out the following few lines of code that will let you have Adsense Section Targeting enabled on your Thesis site in a few seconds.

    // Adsense Section Targeting for posts
    function start_adsense(){
    echo "<!-- google_ad_section_start -->";
    }
    function end_adsense(){
    echo "<!-- google_ad_section_end -->";
    }
    add_action('thesis_hook_before_post','start_adsense');
    add_action('thesis_hook_after_post','end_adsense');

    Most people want to target only the posts – the post means the entire content of your post and just that, cutting out all the garbage info like Related Posts, Comments, Author Byline and so on – which is pretty cool. The above code fully achieves that.

    However, if your site has an active community and there are always engaging conversations then you will for sure get comments that add more value to the posts, in which case it certainly makes sense to target the comments as well. Enter Adsense Section Targeting for Thesis Comments. Of course I am targeting purely the comment text and not the commenter’s name, the datestamp and other such unnecessary info.

    // Adsense Section Targeting for comments
    function start_adsense(){
    echo "<!-- google_ad_section_start -->";
    }
    function end_adsense(){
    echo "<!-- google_ad_section_end -->";
    }
    add_action('thesis_hook_after_comment_meta','start_adsense'); add_action('thesis_hook_after_comment','end_adsense');

    Finally what about Thesis Teasers? If you are using Teasers on the homepage and archive pages then you will want to target the text contained in the teasers. So here is the code for Adsense Section Targeting for Thesis Teasers.

    // Adsense Section Targeting for teasers
    function start_adsense(){
    echo "<!-- google_ad_section_start -->";
    }
    function end_adsense(){
    echo "<!-- google_ad_section_end -->";
    }
    add_action('thesis_hook_before_teaser','start_adsense');
    add_action('thesis_hook_after_teaser','end_adsense');

    Summing it all up, here is the entire code for the ultimate Adsense Section Targeting in Thesis.

    // Adsense Section Targeting
    function start_adsense(){
    echo "<!-- google_ad_section_start -->";
    }
    function end_adsense(){
    echo "<!-- google_ad_section_end -->";
    }
    add_action('thesis_hook_before_post','start_adsense'); // Adsense targeting for posts
    add_action('thesis_hook_after_post','end_adsense');
    add_action('thesis_hook_before_teaser','start_adsense'); // Adsense targeting for teasers (optional)
    add_action('thesis_hook_after_teaser','end_adsense');
    add_action('thesis_hook_after_comment_meta','start_adsense'); // Adsense targeting for comments (optional)
    add_action('thesis_hook_after_comment','end_adsense');

    Warning: Direct copy-pasting of code from this page may give you invalid characters.

  • HOW TO: Create A Member Login Bar In Thesis Header

    In this tutorial I will show you how you can create a cool member bar on your Thesis site that will:

    1. Show a login link to visitors who are not logged in
    2. Upon logging in, redirects users to the same page they were on
    3. Show logout link to logged in users
    4. Show links to dashboard, user profile and so on
    5. Show gravatar of the logged in user

    Coolness aside, it is a great way to present the more frequently used admin links right on the frontend so that the casual contributor doesn’t have to find his way out through a complicated dashboard interface! This is particularly useful for multi-author blogs.

    I prefer to place the member links at the very top, in the Thesis header above the navigation menu, as seen on Bong Buzz. With the following code you can achieve that. You may also want to place it in the sidebar or footer for which you need to call the function in the appropriate hook – should be easy if you are acquainted with Thesis hooks – and modify the HTML and CSS accordingly. You can also add a welcome message to greet your users once they log in.

    Although this guide is written keeping Thesis users in mind, it is applicable to any WordPress theme as well. A generalised code for any WordPress theme is given at the end of this post.

    Let’s start defining a function and name it ‘memberbar’.


    function memberbar() {
    if ( is_user_logged_in() ) { ?>
    <ul class="login">
    <?php global $user_email;
    echo get_avatar($user_email, 13);?>
    <li><a href="/wp-admin/profile.php" title="User Profile"><?php  global $current_user;
    get_currentuserinfo();
    echo($current_user->user_firstname . " " . $current_user->user_lastname . "");
    ?></a></li>
    <li><a href="/wp-admin/post-new.php" title="Write New Post">Write</a></li>
    <li><a href="/wp-admin/" title="Dashboard">Dashboard</a></li>
    <li class="noborder"><a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a></li>
    </ul>
    <?php
    } else {
    ?>
    <ul class="login"><li class="noborder"><a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a></li></ul>
    <?php }
    }

    Now you call the funtion ‘login’ we just created anywhere you wish the member bar to appear. Pretty neat, right? 🙂

    function top_nav_menu() {?>
    <div id="top_nav_menu">
    <ul>
    <li><a href="<?php echo get_bloginfo ('url'); ?>" title="Home">Home</a></li>
    </ul>
    <?php memberbar(); ?>
    </div>
    <?php
    }
    add_action('thesis_hook_before_header', 'top_nav_menu');

    I am quoting the relevant portions from my CSS which will give you a member login bar similar to the one on bongbuzz.net. You should modify it as per your need, especially the measurements.


    #top_nav_menu {
    height:27px;
    }
    #top_nav_menu ul {
    list-style-image:none;
    list-style-type:none;
    margin:0;
    padding-top:7px;
    padding-left:5px;
    float:left;
    }
    #top_nav_menu li {
    border-right: 1px solid #aaa;
    display: inline;
    text-decoration:none;
    }
    #top_nav_menu ul.login {
    padding-left:0;
    float:right;
    padding-right:5px;
    }
    #top_nav_menu li.noborder
    {
    border-right: 0px;
    }
    #top_nav_menu li a {
    padding:0 10px;
    }
    #top_nav_menu li a:hover {
    text-decoration:underline;
    }

    Code for WordPress themes in general:

    <div id="top_nav_menu">
    <ul>
    <li><a href="<?php echo get_bloginfo ('url'); ?>" title="Home">Home</a></li>
    </ul>
    <?php if ( is_user_logged_in() ) { ?>
    <ul class="login">
    <?php global $user_email;
    echo get_avatar($user_email, 13);?>
    <li><a href="/wp-admin/profile.php" title="User Profile"><?php  global $current_user;
    get_currentuserinfo();
    echo($current_user->user_firstname . " " . $current_user->user_lastname . "");
    ?></a></li>
    <li><a href="/wp-admin/post-new.php" title="Write New Post">Write</a></li>
    <li><a href="/wp-admin/" title="Dashboard">Dashboard</a></li>
    <li class="noborder"><a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a></li>
    </ul>
    <?php
    } else {
    ?>
    <ul class="login"><li class="noborder"><a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a></li></ul>
    <?php } ?>
    </div>

    Warning: Direct copy-pasting of code from this page can give you invalid characters.

    Hope you find this useful. 🙂