Answered: How do I create conditions, to control where something appears

Post date: 2021-09-18 07:48:15
Views: 155

You can use  $this->template  to create conditions for different types of pages, much like WordPress.

if ($this->template == 'question') {
    // DO SOMETHING
}

Conditions:

Linked to Navigation

$this->template == 'ask'                          // Ask Page
$this->template == 'qa'                           // Homepage / Q&A Page
$this->template == 'activity'                  // Activity Page
$this->template == 'questions'             // Questions List Page
$this->template == 'hot'                          // Hot Page
$this->template == 'unanswered'        // Unanswered Page
$this->template == 'tags'                       // Tags Page
$this->template == 'categories'           // Categories Page
$this->template == 'users'                     // Users List Page


Single Pages:

$this->template == 'question'              // Single Question Page
$this->template == 'custom'                // Single Page
$this->template == 'search'                  // Search Result Page
$this->template == 'user'                      // Single User Page


Page templates are rendered as a body class in the DOM. You can inspect element to check for other page templates.

Please click Here to read the full story.
 
Other Top and Latest Questions:
The top 10 jobs in the U.S. for 2026 all pay $100,000 or more, according to Indeed
Pentagon is embracing Musk's Grok AI chatbot as it draws global outcry
Iran’s regime in its ‘final days and weeks' after mass protests, Germany’s Merz says
BlackRock's earnings pass our test with flying colors. What about 2026?
DeepMind CEO is talking to Google CEO 'every day' as lab ramps up competition with OpenAI
Boeing secures tentative labor deal with former Spirit AeroSystems workers
South Korea's ex-president Yoon given 5-year jail term in first ruling over martial law
AI startup Replit launches feature to vibe code mobile apps
Trump's proposed ban on buying single-family homes introduces uncertainty for family offices
Trump unveils health-care plan outline as Congress wrestles over Obamacare subsidies