Need Help — got cute with child functions and messed up my RSS

  • dave

    #2703

    So I decided I wanted to take more control over my ads then I could do with stock graphene (i.e., include it on certain posts and certain category rolls but not others). All seems fine with my methodology except that it ends up getting added to my rss feed, thereby destroying the feed. Also the ads show up in the list of my media files in the dashboard view, but don’t really care about that.

    Below is the code I added to my child functions. Note that adrotate_group(1) is calling a plugin that will send back a banner ad.

    site: http://bit.ly/uE0ROy

    Did I get too cute? Is there either a) a better way of inserting ads with this level of control or b) a way to stop this methodology from getting added to the RSS feed?

    Thanks!

    //ADS
    function insert_ads_after_posts(){
    // Make sure it is not the Points Blog
    if ( in_category(3))
    return;
    if (is_single() ){
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    }
    //puts this function where comments template is called inside loop.php in 5th place before facebook comments
    add_filter('comments_template', 'insert_ads_after_posts',5);

    function insert_between_posts1( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 1 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts1' );

    function insert_between_posts3( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 3 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts3' );

    function insert_between_posts5( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 5 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts5' );

    function insert_between_posts7( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 7 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts7' );

    function insert_between_posts9( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 9 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts9' );

    Prasanna SP

    #21587

    Please paste your codes between backticks (in this forum).

    Josh

    #21588

    I would use an action hook to place the widget for the ads. Then I would use a plugin which allows you to specify which page the widget will appear.

    (Added backticks to code above)

    Prasanna SP

    #21589

    +1 to Josh’s suggestion. I’m using the same idea in my site. Try graphene_post_footer in loop.php

    Mod

    Kenneth John Odle

    #21590

    Yep, that’s how to do it. Here’s an old example using the header widget, before action hook widget areas were available:

    https://forum.graphene-theme.com/graphene-support/how-can-i-add-adsense-to-the-background-image-1#post-5040

    The WidgetLogic plugin can control where widgets show up.

    Also moved to Support.

    dave

    #21591

    Josh: Thanks, I think I used the apostrophe instead of the backtick.

    So I went back and just include my old code for the single pages (the top “paragraph” of code) and not the blog rolls and everything seems to work just fine. Prasana, you site (and i assume “graphene_post_footer”) would just have the ad on the single pages?

    So, let me clarify my ask since I guess it only needs to be relevant to the blog rolls. Basically, I am trying to put ads inbetween every three posts except for a certain category.

    Here is a blow up of one:

    function insert_between_posts1( $post ) {
    global $wp_query;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 1 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts1' );

    Could I fix this simply by using a different hook than “the_post”?

    Josh

    #21592

    So you are wanting them to show up on a category page? Or on your front page?

    dave

    #21593

    All category pages but one (i.e., I don’t want it to show in category 3 as shown in the code). The front page (http://bit.ly/uE0ROy) is static. Effectively I am using the category concept to have multiple separate blogs run on a single wordpress site. This otherwise is working well for me. Example of a category blog roll on my site (http://bit.ly/rMsk7I).

    Prasanna SP

    #21594

    Use widget logic and try these conditional tags – http://codex.wordpress.org/Conditional_Tags#A_Category_Page

    dave

    #21595

    I haven’t installed widget logic yet, but I am not sure at this point how it will help. Your reminder about the conditional tags led me to fix the code and now it seems fines.

    Noes the simple is_category() call in the code below. It seems to fix the rss feed and ads showing up in the dashboard. Can’t believe I didn’t do this earlier.

    function insert_between_posts1( $post ) {
    global $wp_query;
    // Make sure it is a category page
    if ( True != is_category())
    return;
    // Make sure it is not the Points Blog
    if ( is_category(3))
    return;
    // Check if we're at the right position
    if ( 1 != $wp_query->current_post )
    return;
    // Display the banner
    ?><div class="post adsense_single"><?php
    echo adrotate_group(1);
    ?></div><?php
    }
    add_action( 'the_post', 'insert_between_posts1' );
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!