Forums / Templates, Stylesheets, Page Layout / How to add a new section that only shows up on the index page but not others

How to add a new section that only shows up on the index page but not others

Locked

Started by graper on 27 Jul 2006, 9:29 PM · Views: 3,136

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
27 Jul 2006, 9:29 PM
#1
graper avatar

graper

New Zenner

Join Date:
Jul 2006
Posts:
50
Plugin Contributions:
0

How to add a new section that only shows up on the index page but not others

To start, I have copied the entire /includes/templates/default_template folder to /includes/templates/mytemplatefolder.

the basic idea of what I want is a section that will only show up on the main index page of the site but not be there when viewing any other part.

I thought of using a banner, but it doesn't need the banner click tracking. thought about using the define_main_page but when I move the code from tpl_index_default.php to tpl_header.php or to tpl_main_page.php it throws an error of not being able to open the file in the require(). To a certain extent I would like to have a secondary header that doesn't show up on any other page then the front page. I just seem to be having a hard time figuring this out and maybe I am over thinking it.

In another CMS they have a variable that can be checked if it is the front page or not. Does ZC have something like this? If not, what would be the easiet way that you all can think of to test if the page being viewed is the front page or not?

Granville
Kirkham Systems, Inc.

Granville [granville (at) kirkhamsystems.com]
Kirkham Systems, Inc.

28 Jul 2006, 2:49 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How to add a new section that only shows up on the index page but not others

thought about using the define_main_page but when I move the code from tpl_index_default.php to tpl_header.php or to tpl_main_page.php it throws an error of not being able to open the file in the require(). Using the "define_main_page does not require one to to MOVE CODE or touch the files at all.

It is editable from the admin > tools > define pages editor

So I guess I missed something that you might have infered or am completely lost as to your comment.

Another Item that you may want to correct now is that one should only copy those files that are altered to the custom template override folders. Not all the files as you have stated. This will become increasingly apparent the first time you upgrade and now have 100's of files that you will need to check & merge instead of just the few that you should be altering.

You should look in the template_default/css/for the css txt file, this outlines using css per page and will allow what you want , and again with out messing with CODE.

Zen-Venom Get Bitten

28 Jul 2006, 1:27 PM
#3
graper avatar

graper

New Zenner

Join Date:
Jul 2006
Posts:
50
Plugin Contributions:
0

Re: How to add a new section that only shows up on the index page but not others

kobra:

Using the "define_main_page does not require one to to MOVE CODE or touch the files at all.

It is editable from the admin > tools > define pages editor

So I guess I missed something that you might have infered or am completely lost as to your comment.

It seems that I did get you lost somewhere as it would seem that you missed the statement of "I would like to have a secondary header that doesn't show up on any other page then the front page". Please note that the header appears above the left and right sidebar columns. I'd like something that takes up the same space but will show up only on the front page but not the others.

I thought I could move the define_main_page tidbit of code, since it only shows up on the front page, into the header area, or to another tpl file so that is shows up under the header but above the sidebars and body area. But in moviing the code that makes the define_main_page appear, an error occurs. So it would seem that the $define_main_pages is only ment to show in the body of any particular page.

As for the problem, forget that I am messing with the code, forget that I copied the template, maybe I threw out a red herring and didn't know it. The most important question that I am putting forth is as follows, is there an easy way to put into the header something that will show up only on the front page and not on any other page? If so, how?

Granville [granville (at) kirkhamsystems.com]
Kirkham Systems, Inc.

28 Jul 2006, 10:13 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: How to add a new section that only shows up on the index page but not others

Did you try customizing

./includes/templates/template_default/common/tpl_main_page.php

This is what you want.

Where you're doing your customization, just check $body_id against "index"
and you'll know if you're on the front page or not.

Good Luck,
Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

28 Jul 2006, 11:26 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to add a new section that only shows up on the index page but not others

graper:

To start, I have copied the entire /includes/templates/default_template folder to /includes/templates/mytemplatefolder.

This, unfortunately, is a bad plan ...

The idea behind the templates and overrides is to separte your code, changes, customization from the original files ...

If you don't touch something, then you did not override or change anything so there is no need to place a file that is untouched into the templates and overrides directories ...

The files are read as:

Look for filename something ...

1 is it in the templates and overrides directory?

2 if not in 1 then get original file

This means you can actually do an entire customization of a site by only touching relatively few files ...

Examples of this are in the Downloads for the templates ...

Language overrides are similar ... unless you changed the define statements in the language file it does not belong in the overrides directory ...

If you change 1 letter ... then, yes ... it goes in the templates and overrides directory for that language file ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

29 Jul 2006, 1:25 AM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: How to add a new section that only shows up on the index page but not others

If you look at the comments at the top of tpl_main_page.php, you will see examples of how to not display this or that on the main page. You can use the

if($current_page_base == 'index' and $cPath == '') {
your code here
}

to display what you want only on the front page.

Now, did you want another block just below the header? Or a different block in place of the header? This will affect the best way to proceed.

29 Jul 2006, 3:24 PM
#7
graper avatar

graper

New Zenner

Join Date:
Jul 2006
Posts:
50
Plugin Contributions:
0

Re: How to add a new section that only shows up on the index page but not others

Scott and Glenn, Thansk for the tips, those were the kind of answers I was looking for.

Glenn, I am wanting to put in a second header, and as I look at the code I think I can put it in the tpl_header.php file, or in the tpl_main_page.php file under the require statement for the header. What do you think would be better?

Linda, I appricate the word of caution and advice, but I had to get a grasp of what file to change to get what I want done, to do that I put in start and end comments in every single file and then looked at the page in a browser to see where things started and ended. Rather then leave them all in the default template files, I copied it all to a new folder. Believe me, the method I used gav mea greater comprehension of what files did what for the layout as well as what files I felt I needed to change. This way when another templates gets added into it, it wouldn't affect the default template, but only show the comments on my template. There was a method to my madness, but thanks for the insight on the override functionality of Zen Cart.

Granville

Granville [granville (at) kirkhamsystems.com]
Kirkham Systems, Inc.

31 Jul 2006, 1:47 AM
#8
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: How to add a new section that only shows up on the index page but not others

I would put the "if" test with your display code at the bottom of tpl_header.php, after the very last line. I suppose it would work fine in tpl_main_page.php, but makes more sense to me in the header file.

1 Sep 2006, 11:10 AM
#9
beatdis avatar

beatdis

New Zenner

Join Date:
Aug 2006
Posts:
13
Plugin Contributions:
0

Re: How to add a new section that only shows up on the index page but not others

I'm trying to do the same thing but I'm not able to obtain what is in my intention:
I've created an "index" folder in "templates/mytemplate/index" with "tpl_header.php" and "tpl_main_page.php" and made some code changes as explained on the files.

The problem is that the custom content is shown on the Index and also when I click on the Categories. I only want my content shown only on the index.

Can you help me? Thanks.

This is an image of what I want to realize:
http://img216.imageshack.us/img216/3495/mywo7.gif

1 Sep 2006, 9:21 PM
#10
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: How to add a new section that only shows up on the index page but not others

graper, either one is ok; just see where it fits best based on what you want to do.
The great thing about the templating system is you can copy a single file to your template
dir, try out a change, rename it to .tmp and you'll be right back to where you started.
It's very easy to switch back and forth that way.

beatdis, look at $cPath. You only want to use your logic when $cPath == ""

Good luck to all,
Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

2 Sep 2006, 1:49 AM
#11
beatdis avatar

beatdis

New Zenner

Join Date:
Aug 2006
Posts:
13
Plugin Contributions:
0

Re: How to add a new section that only shows up on the index page but not others

Thanks swguy, my mistake is the right position in the "tpl_main_page.php" rather than "tpl_header.php".
Now I have what I want...

2 Sep 2006, 3:26 PM
#12
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: How to add a new section that only shows up on the index page but not others

New zenners reading this thread who are not aware of the template system shoul d familiarize themselves with:

http://www.zen-cart.com/forum/faq.php?faq=catalog_issues#faq_template_customize

Doing things this way will save you mucho grief at upgrade time.

Good luck to all,
Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.