WordPress.org

Ready to get started?Download WordPress

Forums

$Referer = Category? (1 post)

  1. ianbee
    Member
    Posted 1 year ago #

    I've sucesfully tracked where clicks are from and then made wordpress show elements based off where that click is from. A code example is this:

    <?php
    $referer = $_SERVER['HTTP_REFERER'];
    
    if ( $referer == "http://www.testdomain.com/testpage" ) {
    	echo '<div id="bgphotos"></div>';
    } else {
        	echo '<div id="bgvideos"></div>';
    }
    ?>

    So this is telling wordpress to display the bgphotos div if it is clicked from http://www.testdomain.com/testpage. This works awesome. I've even done even more coding to track where certain divs are clicked on within a webpage. But, I would like to show an element if it was clicked on from a category.

    Now, I thought the solution would just be to change the $referer to the category webpage. But the problem is, when there are more than one pages of posts for this category, you would have to manually track each category page number... which would take forever.. An example would be:

    if ( $referer == "http://www.testdomain.com/category/test/" ) {
    	//do this }
    
    if ( $referer == "http://www.testdomain.com/category/test/page/2/" ) {
    	//do this }
    
    if ( $referer == "http://www.testdomain.com/category/test/page/3/" ) {
    	//do this }
    
    if ( $referer == "http://www.testdomain.com/category/test/page/4/" ) {
    	//do this }

    As you can see this would just get out of hand, I would have to track every single category page possible. So is there any way to say, just track if something is clicked from a category?? Or any other solution to this problem?

    Any help would be appreciated soo soo soo soo much! :) loll

Topic Closed

This topic has been closed to new replies.

About this Topic