Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.
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.
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');
?>
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.
Presumably the AdSense box is too wide; you’ll need to make it fit in 500px if you want to stop that happening.
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.
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.
1 to 14 of 14