Support » Fixing WordPress » variable google sidebar advert

  • I’m trying to make the sidebar advert on posts fit the content of the post. In other words, if the post is small, I might place one ad in the sidebar; or, if it’s a big post, I would place two ads in the sidebar.

    Is there some way of doing this that’s …. umm… simple ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • It doesn’t seem like WordPress has such function out of the box that returns the length of a post (number of characters or words).

    You can use the Post Word Count plugin to get the number of words per post, but you will have to modified the plugin first.

    Open post-word-count.php, replace echo number_format($totalcount); with return $totalcount;

    Install and activate the plugin.

    Open your theme’s sidebar.php, add the following code to wherever you want to second ad to show up.

    if(mdv_post_word_count(true) >= 100){ //replace 100 with the desire number of words.

    Thanks for the suggestion Haochi, but I’ve solved it without using a plugin by using a Custom Field and evaluating that field within the post template.

    In the post, I have a custom field called “sidebarpost”. If I think the post is smaller or bigger than my default ad, I give a value to this.

    In the template I use :

    <?php $sidebarpost=get_post_meta($post->ID, ‘sidebarpost’, $single = true);
    if ($sidebarpost == “small”) {
    } elseif ($sidebarpost == “button”) {
    } elseif ($sidebarpost == “none”) {
    echo “”;
    } else {include(“sidebaradvertdefault.php”);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘variable google sidebar advert’ is closed to new replies.