Solved

identify joomla frontpage

Posted on 2008-10-17
4
1,537 Views
Last Modified: 2013-12-13
I want a certain piece of code to execute if the frontpage is loaded and another piece of code to be executed on any other page. I have used the attached code but it doesnt work. all pages cause the 'else' part of the conditional to be executed.
<?php if(($_REQUEST['view'] == 'frontpage') || ($_REQUEST['option'] == 'com_frontpage'))
 	$page="home"; ?>
 
 
 <?php if($page=="home") { ?>
			<img src="<?php echo $this->baseurl;?>/templates/<?php echo $this->template;?>/images/FURNITURE-COMPANY_11.jpg" width="697" height="441" alt=""> <?php } 
			  else { echo "page is " . $page; ?> <br /><br /><jdoc:include type="component" /><?php }?>

Open in new window

0
Comment
Question by:nmichele
  • 2
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:AielloJ
AielloJ earned 500 total points
ID: 22739562
nmichele:

Your if statement is controlled by the 'view' and 'option' elements of the $_REQUEST array.  Try printing them out to see of they are the values you're expecting.  You can temporarily use echo statements to print the values or use:

print_r($_REQUEST);

to get a debug printout of everything in the $_REQUEST array.
0
 

Author Comment

by:nmichele
ID: 22739670
Hi AielloJ:
Thanks for the tip. the request array displays the option variable as having the value com_virtuemart, which is the component on the page. However, this component is supposed to display on every page. I would like to identify the home page so that the component details are not displayed in the main content pane of the home page, but are displayed on every other page. which variable of the array would display this? or what code would i need to input?
0
 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
ID: 22739886
I'm assuming the 'view' element didn't have the value 'frontpage' either, since your code would have worked as expected.  The following line of script will return the current page name.

  substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

You can add a line that tests if it's the home page, and take action based on that.  Assuming your home page is named index.php you could use the following code:

  if (substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1) == 'index.php')
  {
    // We are on the home page.
  }
  else
  {
    // We are NOT on the home page.
  }
0
 

Author Comment

by:nmichele
ID: 22753331
Thanks AielloJ :-)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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