variable google sidebar advert (3 posts)

  1. taglad
    Posted 8 years ago #

    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 ?

  2. haochi
    Posted 8 years ago #

    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.
  3. taglad
    Posted 8 years ago #

    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");

Topic Closed

This topic has been closed to new replies.

About this Topic