我不是一个很好的程序员,我的技术主要包括复制粘贴和编辑,直到它工作为止。
我在一个joomla2.5网站的index.php中有这段代码,它只在主页上输出某种css样式。
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()): ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php endif; ?>
这还可以,但现在我想对所有不是主页的页面使用'else'语句,以提供一个可选的最小高度css。这应该很容易吧?然而,我的语法有问题,因为我无法使它工作。那么它应该怎么写呢?感谢
什么是无效语法?
它应该只是一个else:
。
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else: ?>
#contentonderaan {min-height: YOUR_HEIGHTpx;}
<?php endif; ?>
</style>
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else?>
#contentonderaan {min-height: 100px;} //giving min height
<?php endif; ?>
</style>
快乐编码:(
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php }
else{
?>
Some other thing
<?php } ?>
您可以使用大括号:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
?>
<?php if ($menu->getActive() == $menu->getDefault()){ ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php }else{ ?>
<!-- foo -->
<?php } ?>
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php } else { ?>
<style type="text/css">
#contentonderaan {min-height: 500px;}
</style>
<?php } ?>
或者您也可以使用else:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()): ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php else: ?>
<style type="text/css">
#contentonderaan {min-height: 500px;}
</style>
<?php endif; ?>
使用简写语法提高可读性:
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else: ?>
#contentonderaan {min-height: 642px;}
<?php endif; ?>
</style>