WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with variables and session variables (8 posts)

  1. SenseiAntonio
    Member
    Posted 6 years ago #

    Hello everyone,

    In my blog (www.tecnobot.com), I have installed the AdSense Sharing Revenue and Earnings Plugins (http://adsense.ayanev.com/how-to-use-this-plugin/).

    In this plugin, I specify a php function in the Google Adsense code, so the Adsense client code changes with the adsense client code of each author, inserted previously in the administration panel.

    The first adsense advertisement includes this line of php code, in which, I presume, the variable is defined:

    <?php $id=$post->post_author; $google_id = kd_get_google_id($id); echo
    $google_id; ?>

    This outputs the adsense code of each author in his articles.

    The plugin creator said that in the next advertisements or Google Adsense blocks, and in the sidebar I have to put this php code:

    <?php echo $google_id; ?>

    The problem is that since the first advertisement is located in the single.php and the second in the sidebar.php, the variable google_id is not carried and it does not output anything in the sidebar.

    The author suggested to store the variable as a session variable. I presume that is for the variable to be carried along the blog in those pages.

    How do I define that variable as a session variable or similar, so the variable outputs the two times?

    Thank you very much in advance,

    Antonio Bustamante
    Tecnobot.com

  2. iscifi
    Member
    Posted 6 years ago #

    php.net is the best resource for that type of coding, look at isset, and session varibles...

  3. SenseiAntonio
    Member
    Posted 6 years ago #

    The information there is not very clear to me. How can I do this in WordPress? Sorry, but I am not precisely a PHP expert ;-)

  4. iscifi
    Member
    Posted 6 years ago #

    wordpress uses PHP, so you need to write the code that stores your neded information in a session varible , then the sidebar php code needs to refer to that session varble, its going to take some php know-how, and some trial and error on your part to make the modifications.

    sorry to say its not as easy as hey type

    blah=something, it does take some coding to get it done and I would suggest working with the plugin author if they will help you out at all.

  5. SenseiAntonio
    Member
    Posted 6 years ago #

    And is there a simpler way to do this? Such as, for example, defining the variable in the header, or something like that?

    I say this because I can handle some PHP things but not to the point where I define session variables. I somehow understand the concept but not how to apply it.

    Do you have any idea of a simpler way to do this?

  6. SenseiAntonio
    Member
    Posted 6 years ago #

    Anyone?

  7. iscifi
    Member
    Posted 6 years ago #

    Sensei

    Sure you can define it inside header.php since that is called on every post, page etc. Then you can read the session varible in the sidebar and change the adsense id based on what is in the header.

    Problem is what happens if you have 2 or more authors and wordpress by default shows all posts regardless of who wrote it? Based on this that most recent author would be the one who's adsense ID would be set in the session variable, so adsense credit wouldn't be given to the other author.

    You would have to devise a way to only show posts by author X then adsense would display ads for author X only. Make sense?

    I use adsense myself, but the entire blog associate ID is for the site not multiple authors, that works perfect for my site, but trying to drive ads based on the author is going to put a bit of overhead on you programing in php and also determine the fairest way of showing ads based on author.

    I guess you could have each author have its own category and make the blog only show category X for author X, category Y for author Y and so on?

  8. SenseiAntonio
    Member
    Posted 6 years ago #

    Yes, you are right. I will try to figure out some solution to this. It doesnt sound so difficult, after all.

    Thank you very much, scifi, for your help ;-)

    Antonio

Topic Closed

This topic has been closed to new replies.

About this Topic