Not signed in (Sign In)

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorVincent
    • CommentTimeAug 22nd 2007 edited
     
    Hi

    I'm using your theme for my site http://bettersmarterkids.com.

    I intend to add an adsense to the all the post, but I couldn't find the single post file in Tarski Theme, can you tell me how can I add the google adsense code to single post file?

    Appreciate your quick reply.

    Thanks
    Vincent
  1.  

    Short version? Write a plugin to integrate the theme and the adsense code. Tarski uses a single loop file to serve all the different page files, to reduce duplication. Have a look at the code I posted on this thread, that should give you an idea of how to accomplish what you want.

    • CommentAuthorVincent
    • CommentTimeAug 23rd 2007
     
    Hi Ben

    I've created another php file as you mentioned to the admin and activated the plugin.

    What next? (sorry I'm not a savvy web progammer), can you lead you what should I do next? I looked at the theme editor side, but couldn't find the single post file.

    Meantime, I need to do another changes for the background color. I intend to use different background color but the homepage color remain as white. I looked at the css file, the current setting background color as #fff, after I change the color, the homepage color change as well.

    Appreciate your help so much, thanks!!
    Vincent
  2.  

    You don’t need to change the single post file; that’s the point of writing the plugin. The plugin code should look like this, with your AdSense code included where I’ve indicated (if it’s mostly HTML, you’ll need a closing PHP tag before it, and an opening one before starting the rest of the plugin).

    <?php /* Plugin Name: AdSense in Tarski Plugin URI: http://tarskitheme.com/ Description: Displays Google adverts on single post pages Author: Ben Eastaugh Version: 1.0 Author URI: http://extralogical.net/ */ function tarski_output_adsense() { if(is_single()) { // AdSense code goes here } } add_action('th_postend','tarski_output_adsense'); ?>

    As far as the CSS stuff goes, you need to create an alternate style with your own style rules. If you want the styles to change depending on which page the visitor accesses, you’ll need some PHP in there too. One possibility is a plugin which detects the page and serves different styles depending on which page is accessed (you’ll need to write two CSS files and change the links in the plugin appropriately).

    <?php /* Plugin Name: Variable Backgrounds Plugin URI: http://tarskitheme.com/ Description: Changes background colour depending on page Author: Ben Eastaugh Version: 1.0 Author URI: http://extralogical.net/ */ function tarski_vary_background() { if(is_home()) { echo '<link rel="stylesheet" href="home.css" type="text/css" media="screen,projection" />'; } else { echo '<link rel="stylesheet" href="other.css" type="text/css" media="screen,projection" />'; } } add_action('wp_head','tarski_vary_background'); ?>

    • CommentAuthorVincent
    • CommentTimeAug 23rd 2007
     
    Ben

    How come is a text file??

    <?php /*
    Plugin Name: AdSense in Tarski
    Plugin URI: http://tarskitheme.com/
    Description: Displays Google adverts on single post

    pages
    Author: Ben Eastaugh
    Version: 1.0
    Author URI: http://extralogical.net/
    */
    function tarski_output_adsense() {
    if(is_single()) {
    <script type="text/javascript"><!--
    google_ad_client = "pub-";
    google_ad_width = 336;
    google_ad_height = 280;
    google_ad_format = "336x280_as";
    google_ad_type = "text_image";
    google_ad_channel = "";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "006A80";
    google_color_text = "333333";
    google_color_url = "8FBF60";
    //--></script>
    <script type="text/javascript"
    }
    }
    add_action('th_postend','tarski_output_adsense');
    ?>

    Where to place the closing php tag, and an opening before starting the plugin??

    Thanks in advance!
  3.  

    Like this:

    <?php /* Plugin Name: AdSense in Tarski Plugin URI: http://tarskitheme.com/ Description: Displays Google adverts on single post pages Author: Ben Eastaugh Version: 1.0 Author URI: http://extralogical.net/ */ function tarski_output_adsense() { if(is_single()) { ?> <script type="text/javascript"><!-- google_ad_client = "pub-"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text_image"; google_ad_channel = ""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "006A80"; google_color_text = "333333"; google_color_url = "8FBF60"; //--></script> <script type="text/javascript" <?php } } add_action('th_postend','tarski_output_adsense'); ?>

    Save it as tarski-adsense.php or something in your wp-content/plugins directory, and then activate it as normal.

    • CommentAuthorVincent
    • CommentTimeAug 23rd 2007
     
    Ben

    Thank you so much.

    I've added the tarski-adsense.php and its work, but how come the sidebar move downward? Is that anywhere to restore back to the right side?
  4.  

    Presumably the AdSense box is too wide; you’ll need to make it fit in 500px if you want to stop that happening.

    • CommentAuthorVincent
    • CommentTimeAug 24th 2007
     
    Bravo Ben

    The problem solved. Thank you so much!

    I'm glad to see such a dedicated wordpress webmaster and most willingly to help members to solve their problem.

    I salute you.

    Vincent
    • CommentAuthoraustinhk
    • CommentTimeSep 5th 2007 edited
     
    I managed to get it to work on a site. Thanks...it's something I had been looking for.

    My question is how do I apply the same principle to all posts instead of just a single post (e.g on the frontpage)? Where do I make changes to make it work, I tried a few things and that did not work?

    Also, how do I place it above the post instead of under? Thanks. I am usually capable of making a few changes in code but I can not get this to work when I make changes!
  5.  

    My question is how do I apply the same principle to all posts instead of just a single post (e.g on the frontpage)?

    Take out the bit of code that checks to see if it’s a single post.

    To put it above the post you’ll either have to hack the theme or use the loop_start action, i.e.

    add_action('loop_start','tarski_output_adsense');

    Not tried this out so it may not work as intended.

    • CommentAuthoraustinhk
    • CommentTimeSep 6th 2007
     
    Thanks Ben...can't wait to adopt the changes when I get a chance tonight!
  6.  

    Let me know if you run into problems and I’ll try to figure it out for you. Doing it this way might seem like more work—it is more work, at least initially—but it does bring rewards in the longer term because it’s easier to edit, and lets you upgrade the theme without needing to save your changes and then hack them back in.

    • CommentAuthoraustinhk
    • CommentTimeSep 19th 2007 edited
     
    Thanks again Ben...finally got a chance to try it out and results are as follows;

    Take out the bit of code that checks to see if it’s a single post.

    This worked and displayed on homepage and on single post!

    add_action('loop_start','tarski_output_adsense');

    This only outputs to the top of the first post on the homepage and not the rest of the posts. But it works on single posts!