Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Simple php question


Chris Perkins

Recommended Posts

My shop looks like this:

 

http://www.predecimal.com/shop/

 

I'm not very clued up with php and the like, and I'd like to know how I can make the 'Coins For Sale' link across the top of each page (in header.php) to link to the list of categories within the 'Coins For Sale' category, so that clicking on it brings the visitor to here:

 

http://www.predecimal.com/shop/index.php?c...=coins-for-sale

 

(which is the same as clicking 'Coins For Sale' on the left Categories menu)

 

What code to I need to insert in the header.php file to make this happen?

 

And while I'm here, how do I insert the number of 'Coins For Sale' into the text of a page, for example, if I want to say on the main page that there are 'Currently x coins for sale' (where x = the total no. of items in the coins for sale category...currently 508)?

 

Thanks,

 

Chris

Link to comment
Share on other sites

You already have a 'Coins for Sale' link that shows up in the header/menu across the top on all pages, but it currently points to '/shop/coins_for_sale.php'. You can simply change it to '/shop/index.php?cName=coins-for-sale'

 

As for showing the count, you can just add

<? echo tep_count_products_in_category(1); ?> // Where 1 is the category number

 

So your link should read

<a href="/shop/index.php?cName=coins-for-sale">Coins for Sale (<? echo tep_count_products_in_category(1); ?>)</a>

 

(Replacing the 1 with the category number you are using of course.

At least I think the above should work, I'm pretty new to this myself.

 

-Tim

www.honeyrunapiaries.com

Link to comment
Share on other sites

You already have a 'Coins for Sale' link that shows up in the header/menu across the top on all pages, but it currently points to '/shop/coins_for_sale.php'. You can simply change it to '/shop/index.php?cName=coins-for-sale'

 

Yes, the link that's there is just there to remind me to make it work, ignore what it points to at the moment. That link would work of course, but is messy if I change the catagory name in the future. I wondered how I could change it to point at the same place but using the variable that represents the catagory instead of a hard link.

 

Thanks for the number answer, I'll try that in just a moment!

 

Chris

Link to comment
Share on other sites

You might have pasted it in the middle of something it shouldn't be in (such as in the middle of a block of php code). The code works fine for me. I just pasted it into a copy of my index.php and it works fine. See here at the very bottom of the page. (It even took into account the SEO contribution I installed).

 

My index2.php file reads (near the bottom)

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<a href=<? echo tep_href_link(FILENAME_DEFAULT, 'cPath=21'); ?>>Coins for Sale (<? echo tep_count_products_in_category(21);?>)</a>

<!-- footer_eof //-->

 

 

-Tim

Link to comment
Share on other sites

Yes, that does work doesn't it.

 

I tried to enter it in the langugages/english/index.php within the html formatted text for the page. I need to put it in the text so that it just appears to be part of the text.

 

I'll check it works on its own at the end, but if you know how I can squeeze it into the define('TEXT_MAIN', part that would be super.

Link to comment
Share on other sites

You would have to enter it something like the following:

 

define('TEXT_MAIN',

'This is a test<br>' .

'<a href=' . tep_href_link(FILENAME_DEFAULT, 'cPath=21') . '>Coins for Sale (' . tep_count_products_in_category(21) . ')</a>');

Link to comment
Share on other sites

Basically you are just createing a big text string assigned to the variable TEXT_MAIN

It can be all on line line (as most of the text in the language files are). But for large stuff I like

to break it up on multiple lines for ease of reading and editing. The period '.' between each quoted string (or function call that returns a string) tells php to put the stuff all together into one big string.

So:

 

define('TEXT_MAIN',

'This is the first part of text main...<br>' .

'And another line of text main. Click on ' .

'<a href=' . tep_href_link(FILENAME_DEFAULT, 'cPath=21') . '>Coins for Sale (' . tep_count_products_in_category(21) . ')</a>' .

' and it will take you to another page.<br>' .

' And here is text after the link.'

);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...