Solved

identify joomla frontpage

Posted on 2008-10-17
4
1,535 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now