0

我不是一个很好的编码员,我的技术主要包括复制粘贴和编辑,直到它起作用。

我的 index.php 中有一个 joomla 2.5 站点的代码,它只在主页上输出某种 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。这应该很容易吧?但是我的语法有问题,因为我无法让它工作。那么应该怎么写呢?谢谢

4

6 回答 6

6

你不工作的语法是什么?

它应该是一个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>
于 2013-04-18T14:17:47.993 回答
1
<?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>

快乐编码:)

于 2013-04-18T14:21:15.593 回答
0
<?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 } ?>
于 2013-04-18T14:18:31.087 回答
0

您可以使用大括号:

<?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 } ?>
于 2013-04-18T14:19:08.527 回答
0
<?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; ?>
于 2013-04-18T14:19:09.267 回答
0

使用简写语法以提高可读性:

<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
    #contentonderaan {min-height: 462px;}
<?php else: ?>
    #contentonderaan {min-height: 642px;}
<?php endif; ?>
</style>
于 2013-04-18T14:20:18.163 回答