我们遇到以下Joomla的问题! 3.1网站: http://www.kurapotheke-igls.at/
包含两个css文件:
<link rel="stylesheet" href="//media/jui/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="//media/jui/css/bootstrap-responsive.css" type="text/css" />
这里路径错误,前面有两条斜线,不应该在那里。我用YSlow测试它,这两个文件导致网站的极端加载时间。
奇怪的是,当我查看网站代码时,这两个文件包括两次:
<link rel="stylesheet" href="http://www.kurapotheke-igls.at/media/jui/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="http://www.kurapotheke-igls.at/media/jui/css/bootstrap-responsive.css" type="text/css" />
<link rel="stylesheet" href="//media/jui/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="//media/jui/css/bootstrap-responsive.css" type="text/css" />
这是index.php文件的代码:
<?php
defined('_JEXEC') or die;
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$this->language = $doc->language;
// Add current user information
$user = JFactory::getUser();
// Add Bootstrap Framework
JHtml::_('bootstrap.framework');
JHtml::_('stylesheet', JUri::root() . 'media/jui/css/bootstrap.min.css');
JHtml::_('stylesheet', JUri::root() . 'media/jui/css/bootstrap-responsive.css');
// Add page class suffix
$itemid = JRequest::getVar('Itemid');
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getItem($itemid);
$params = $menu->getParams( $active->id );
$pageclass = $params->get( 'pageclass_sfx' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<jdoc:include type="head" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- Stylesheets -->
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/icons/css/font-awesome.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/css/k2style.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/css/joomla.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/css/template.css" type="text/css" />
<!-- Styles -->
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles/<?php echo $this->params->get('templateStyles'); ?>.css" type="text/css" />
<?php if (isset($_GET['style'])) { $styles = $_GET['style']; }
if (isset($styles)) { ?>
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles/style<?php
if ($styles == '1') {echo '1';} elseif ($styles == '2') {echo '2';} elseif ($styles == '3') {echo '3';} elseif ($styles == '4') {echo '4';} elseif ($styles == '5') {echo '5';} elseif ($styles == '6') {echo '6';} elseif ($styles == '7') {echo '7';} elseif ($styles == '8') {echo '8';} elseif ($styles == '9') {echo '9';} elseif ($styles == '10') {echo '10';} ?>.css" type="text/css" /> <?php }
else { echo ""; } ?>
<!-- Google Font -->
<link href='http://fonts.googleapis.com/css?family=<?php echo ($this->params->get('googleFont')) ? $this->params->get('googleFont') : "Open+Sans"; ?>' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=<?php echo ($this->params->get('textLogoGoogleFont')) ? $this->params->get('textLogoGoogleFont') : "Open+Sans"; ?>' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
<?php // Parameters
require("admin/params.php"); ?>
<?php // Google Analytics Tracking Code
if($analyticsCode) {echo '<script type="text/javascript">'; echo $analyticsCode; echo '</script>';}?>
<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/backtop/backtop.js"></script>
</head>
你知道为什么joomla包含这个错误的文件吗?
答案 0 :(得分:1)
我遇到了同样的错误,在我的情况下,主页上发布的模块试图加载bootstrap.min.css,但该模块的php文件拼写错误。该路径在媒体目录之前是斜线,生成到// media / jui的链接... 尝试在模块代码中搜索“/media/jui/css/bootstrap.min.css”并删除斜杠。它对我有用。
JHTML::stylesheet('media/jui/css/bootstrap.min.css');
答案 1 :(得分:0)
尝试使用以下内容,而不是使用Joomla的JHtml
方法。
所以替换这个:
$doc->addStyleSheet('media/jui/css/bootstrap.min.css');
$doc->addStyleSheet('media/jui/css/bootstrap-responsive.css');
用这个:
JHtml::_('stylesheet', JUri::root() . 'media/jui/css/bootstrap.min.css');
JHtml::_('stylesheet', JUri::root() . 'media/jui/css/bootstrap-responsive.css');
答案 2 :(得分:0)
Addstylesheet必须包含完整的网址路径,除非它是从模板链接到的。
所以$doc->addStyleSheet(JUri::base().'media/jui/css/bootstrap.min.css');
应该有效。
参考:http://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page
我相信来自模板你可以使用$ this-&gt;和相对网址,即$this->addStyleSheet('media/jui/css/bootstrap.min.css');