Storing variable in wordpress blog main index.php and accessing variable inside blog

Discussion in 'Blogging' started by globalcashsite, Dec 18, 2011.

  1. #1
    I want to store one url variable in wordpress's main index.php and then access this variable in blog's sidebars, headers and posts. How to do this? For example http://www.abcxyz.com/index.php?show=yes

    Now I want to access this show variable in blog sidebar, header and posts?

    GCS
     
    globalcashsite, Dec 18, 2011 IP
  2. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #2
    You'll need this to execute php in sidebars widgets and post content if you do not plan to edit the template files directly:
    http://wordpress.org/extend/plugins/exec-php/

    Let's see. To grab the tagged parameter.

    Here's how I do it with WP Traffic Tools to grab the referring search query:

    
    $referrer= $_SERVER['HTTP_REFERER'];
    if (strstr($referrer,'google.com')||strstr($referrer,'bing.com')||strstr($referrer,'yahoo.com')||strstr($referrer,'q='))
    {
    	preg_match('/q=(.*?)(&|\z)/', $referrer,$matches);
    	$google_query = $matches[1];
    }
    
    
    PHP:
    That would need to go into the top of your theme's header.php file.
     
    adbox, Dec 19, 2011 IP