Using Conditionals in Plugins to show content on specific pages/sections

Discussion in 'Tutorials' started by Mark, May 1, 2013.

  1. Mark
    • Staff

    Mark Administrator Staff Member

    in this tutorial we will look at using conditionals in plugins to show/hide content on certain pages using simple PHP.

    PHP:
    //Show on Custom Pages Only
    if(isset($FORM['page'])) {
     
    $TMPL['something'] = 'This is visible only on custom pages';
     
    }
     
     
     
     
    //Show on a specific custom page that has ID of advertise
    if($FORM['page'] == 'advertise') {
     
    $TMPL['something'] = 'This is visible only on the advertise custom page';
     
    }
     
     
    //Show on search results page
    if($FORM['a'] == 'search') {
     
    $TMPL['something'] = 'This is visible only on the search results page';
     
    }
     
     
    //Show on stats pages
    if($FORM['a'] == 'stats') {
     
    $TMPL['something'] = 'This is visible only on the users stats page';
     
    }
     
    //Show on user control panel
    if($FORM['a'] == 'user_cpl') {
     
    $TMPL['something'] = 'This is visible only on the users control panel ';
     
    }
     
     
     
    //Show on home page and all ranking pages, hide on search, stats, user control panel etc
    if(!isset($FORM['a'])) {
     
    $TMPL['something'] = 'This is visible only on home page and all ranking pages ';
     
    }
     

    in each of the above examples we used $TMPL['something'] for the tag, when used in a template that would look like {$something}
  2. Basti
    • Staff

    Basti Administrator Staff Member

    To extend it, $TMPL['something'] should be initialized at the first line, to avoid php notices in newer php version, like this
    Code:
    $TMPL['something'] = '';
    daannet likes this.
  3. daannet

    daannet Member

    Spend time to something simple haha
    PHP:
    //Show on home page and all ranking pages, hide on search, stats, user control panel etc
    if(!isset($FORM['a'])) {
     
    $TMPL['something'] = 'This is visible only on home page and all ranking pages ';
     
    }
  4. armaclans
    • Licensed

    armaclans Member

    What hook would this go into?
  5. Mark
    • Staff

    Mark Administrator Staff Member

    This can go into any hook.

Share This Page