Solved

Trying to control page layout tags with php if statements

Posted on 2013-06-01
1
621 Views
Last Modified: 2013-06-03
Hello,

I am working on a joomla website (http://testingtesting1.info/jutwynne/)

The homepage is assigned to "Featured Articles", but I will not have any "featured articles", its only assigned to this because the menu has to be assigned to something.

Now when you are on the homepage I have this if statment

<?php if ($this->countModules('latest-news')) : ?>

Open in new window


The latest-news module is only assigned to the homepage, therefore if you are on the homepage only the specific homepage layout tags and the other modules assigned to the homepage will load.

Code here:
<div id="home">
						<div id="lft-column" class="float-left">
							<jdoc:include type="modules" name="latest-news" style="none" />
						</div>
						<!-- END LEFT -->	
						<div id="rt-column" class="float-right">
							<div id="featured-video">
								<div class="title">
									<jdoc:include type="modules" name="featured-video-title" style="none" />
								</div>
									<jdoc:include type="modules" name="featured-video" style="none" />
							</div>
							<!-- END RECENT -->
							<div id="social-feed">
								<div class="title">
									<jdoc:include type="modules" name="social-feed-title" style="none" />
								</div>
									<jdoc:include type="modules" name="social-feed" style"none" />
							</div>
							<!-- END SOCIAL-FEED -->
						</div>
						<!-- END RIGHT -->				
					</div>
					<!-- END HOME -->

Open in new window


Now this works fine. If you go anywhere else on the website the code tags specific to the homepage vanish and only the code for the article appears.

Now for the article specific layout tags I have this if statement:

<?php /*see if we are on the homepage, if not load article tags and modules*/ 
				$menu = &JSite::getMenu();
				 if (JRequest::getInt('Itemid') != $menu->getDefault()) : ?>

Open in new window


The issue is that the above code does not seem to be working on the actual homepage. The article specific layout tags (see below) will load anyway regardless if you are on the homepage - but it should NOT load at all when on the homepage. Additionally, the article tags are empty (no content is contained within them).

If you use firebug or whatever developer you will see right after the <div id="home"> declaration this:

<div id="article" class="float-left">
<div id="additional-links" class="float-right"> </div>

Open in new window


Obviously I am missing some logic flow, but for the life of me I seem unable to locate this missing logic.

Also, related or unrelated to the above issue - when on the homepage and you click on the first two READ MORE links within the text bubbles (Category 3, Category 2) the article loads within the homepage inside the article tags (with both homepage layout and article layout both loaded), but if you click the READ MORE link for Category 1 you are directed (as you are suppose to for the first 2 read more links) to the actual article page. Any ideas why this is happening?

Below is all of my code.

Any help would be great.

Thanks,

Morgan

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  Templates.jutwynne
 *
 * @copyright   Copyright (C) 2007 - 2013 TotalEEYou.com, Inc. All rights reserved.
 */

defined('_JEXEC') or die;

// Getting params from template
$params = JFactory::getApplication()->getTemplate(true)->params;

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;

// Detecting Active Variables
$option   = $app->input->getCmd('option', '');
$view     = $app->input->getCmd('view', '');
$layout   = $app->input->getCmd('layout', '');
$task     = $app->input->getCmd('task', '');
$itemid   = $app->input->getCmd('Itemid', '');
$sitename = $app->getCfg('sitename');

if($task == "edit" || $layout == "form" )
{
	$fullWidth = 1;
}
else
{
	$fullWidth = 0;
}

// Add JavaScript Frameworks
JHtml::_('bootstrap.framework');

// Add Stylesheets
$doc->addStyleSheet('templates/'.$this->template.'/css/template.css');

// Load optional RTL Bootstrap CSS
JHtml::_('bootstrap.loadCss', false, $this->direction);

// Add current user information
$user = JFactory::getUser();

// Logo file or site title param
if ($this->params->get('logoFile'))
{
	$logo = '<img src="'. JURI::root() . $this->params->get('logoFile') .'" alt="'. $sitename .'" />';
}
elseif ($this->params->get('sitetitle'))
{
	$logo = '<span class="site-title" title="'. $sitename .'">'. htmlspecialchars($this->params->get('sitetitle')) .'</span>';
}
else
{
	$logo = '<span class="site-title" title="'. $sitename .'">'. $sitename .'</span>';
}
?>
<!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; ?>">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<jdoc:include type="head" />
	<?php
	// Use of Google Font
	if ($this->params->get('googleFont'))
	{
	?>
		<link href='http://fonts.googleapis.com/css?family=<?php echo $this->params->get('googleFontName');?>' rel='stylesheet' type='text/css' />
		<style type="text/css">
			h1,h2,h3,h4,h5,h6,.site-title{
				font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFontName'));?>', sans-serif;
			}
		</style>
	<?php
	}
	?>
	<!--[if lt IE 9]>
		<script src="<?php echo $this->baseurl ?>/media/jui/js/html5.js"></script>
	<![endif]-->
	<script type="text/javascript" src="http://testingtesting1.info/jutwynne/templates/jutwynne/js/background.js" ></script>
</head>

<body>
	<div id="bg" >
		<!-- Body -->
		<div class="container<?php echo ($params->get('fluidContainer') ? '-fluid' : '');?>">
			<!-- Header -->
			<div id="header">
				<div class="header-inner clearfix">
					<a class="brand pull-left" href="<?php echo $this->baseurl; ?>">
						<?php echo $logo;?> <?php if ($this->params->get('sitedescription')) { echo '<div class="site-description">'. htmlspecialchars($this->params->get('sitedescription')) .'</div>'; } ?></a>
					<div class="header-search pull-right">
						<jdoc:include type="modules" name="position-0" style="none" />
					</div>
					<?php if ($this->countModules('nav-menu')) : ?>
						<div id="top-nav">
							<jdoc:include type="modules" name="nav-menu" style="none" />
						</div>
					<?php endif; ?>
				</div>
			</div>
			<!-- END HEADER -->
			<!-- BEGIN Content -->
			<div class="content" >
				<?php if ($this->countModules('latest-news')) : ?>
					<div id="home">
						<div id="lft-column" class="float-left">
							<jdoc:include type="modules" name="latest-news" style="none" />
						</div>
						<!-- END LEFT -->	
						<div id="rt-column" class="float-right">
							<div id="featured-video">
								<div class="title">
									<jdoc:include type="modules" name="featured-video-title" style="none" />
								</div>
									<jdoc:include type="modules" name="featured-video" style="none" />
							</div>
							<!-- END RECENT -->
							<div id="social-feed">
								<div class="title">
									<jdoc:include type="modules" name="social-feed-title" style="none" />
								</div>
									<jdoc:include type="modules" name="social-feed" style"none" />
							</div>
							<!-- END SOCIAL-FEED -->
						</div>
						<!-- END RIGHT -->				
					</div>
					<!-- END HOME -->
				<?php endif; ?>
				
				<?php /*see if we are on the homepage, if not load article tags and modules*/ 
				$menu = &JSite::getMenu();
				 if (JRequest::getInt('Itemid') != $menu->getDefault()) : ?>
					<?php /*float article left if position rt-column is selected*/
					if ($this->countModules('rt-column')) : ?>
						<!-- BEGIN ARTICLE -->
						<div id="article" class="float-left">
							<!-- Begin Content -->
								<div id="article-top"></div>
								<jdoc:include type="component" />
								<div id="article-btm"></div>
							<!-- End Content -->
						</div>
						<div id="additional-links" class="float-right">
							<jdoc:include type="modules" name="rt-column" style="none" />
						</div>
						<!-- END ARTICLE -->
					<?php endif; ?>
					<?php /*float article right if position lft-column is selected*/
					if ($this->countModules('lft-column')) : ?>
						<!-- BEGIN ARTICLE -->
						<div id="article" class="float-right">
							<!-- Begin Content -->
							<div id="article-top"></div>
							<jdoc:include type="component" />
							<div id="article-btm"></div>
							<!-- End Content -->
						</div>
						<div id="additional-links" class="float-left">
							<jdoc:include type="modules" name="lft-column" style="none" />
						</div>
						<!-- END ARTICLE -->
					<?php endif; ?>
				<?php endif; ?>
				</div>
			</div>
			<!-- END CONTENT -->
		<!-- END CONTAINER -->
		<!-- Footer -->
		<div id="footer">
			<div class="container">
				<jdoc:include type="modules" name="footer" style="none" />
				<p>&copy; <?php echo $sitename; ?> <?php echo date('Y');?></p>
			</div>
			<!-- END CONTAINER -->
		</div>
		<!-- END FOOTER -->
		<jdoc:include type="modules" name="debug" style="none" />
		<jdoc:include type="message" />
	</div>
</body>
</html>

Open in new window

0
Comment
Question by:Morgan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
Morgan earned 0 total points
ID: 39217118
I have found an answer. I had to change the if statement to:

<?php /*see if we are on the homepage, if not load article tags and modules*/ 
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() != $menu->getDefault()) : ?>

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question