Solved

identify joomla frontpage

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

759 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

21 Experts available now in Live!

Get 1:1 Help Now