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

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}
 

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

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 ';
 
}
 
Top