Zen Cart Logo
Forums / General Questions / Replacing a text string on a page

Replacing a text string on a page

Views: 2,167

Results 21 to 32 of 32
16 Dec 2011, 5:28 PM
#21
rescoccc avatar

rescoccc

Totally Zenned

Join Date:
May 2010
Location:
WA State
Posts:
1,700
Plugin Contributions:
2

Replacing a text string on a page

Would it be possible to create an SQL patch that accomplishes this? Or, am I not understanding how category and product titles are stored?

16 Dec 2011, 6:05 PM
#22
gjh42 avatar

gjh42

Black Belt

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

Re: Replacing a text string on a page

The OP wants to use only one database for all of these sites, and output keywords specific to each site.

16 Dec 2011, 6:11 PM
#23
rescoccc avatar

rescoccc

Totally Zenned

Join Date:
May 2010
Location:
WA State
Posts:
1,700
Plugin Contributions:
2

Re: Replacing a text string on a page

Ah, okay. I missed that.

16 Dec 2011, 7:03 PM
#24
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

Stuck on this bit on the product_listing.php module

    } else {
      $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . **$listing->fields['product_name'] **. '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';

Bit in bold is the string that brings up the product name, but everything ive tried has brought it up blank. :unsure:

16 Dec 2011, 8:12 PM
#25
gjh42 avatar

gjh42

Black Belt

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

Re: Replacing a text string on a page

You have a typo there - the field is products_name.

$listing->fields['products_name']

You haven't said exactly what happened when you tried the function. If you want your version to be more maintainable, you really need to develop a cleaner method than inserting a bunch of individualized PHP into every file you want to affect.

17 Dec 2011, 10:56 AM
#26
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

gjh42:

You have a typo there - the field is products_name.

$listing->fields['products_name']

You haven't said exactly what happened when you tried the function. If you want your version to be more maintainable, you really need to develop a cleaner method than inserting a bunch of individualized PHP into every file you want to affect.

Yes sorry, ignore the Typo. It just came out blank where the text should have been. I'm not really concerned about the maintenance. I have a note of the files changed and the code is inserted at the top of each php file. I'd just like to get it working first then look at a way of doing a global function.
Posted via Mobile Device

17 Dec 2011, 5:04 PM
#27
gjh42 avatar

gjh42

Black Belt

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

Re: Replacing a text string on a page

A str_replace() example from the PHP manual:```php
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);
// Provides: You should eat pizza, beer, and ice cream every day

7 Feb 2012, 5:23 PM
#28
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

Right, I didnt continue with this, but I have another issue Im trying to get around.

I know that you cannot mark attributes temporarily out of stock, you have to delete them, and re-add them, or replace one with one that says 'out of stock' in the title of the attribute etc..

Now what about instead of all that, you mark the attribute display only so it can't be checked out, put a price factor of say +£999 to it, but then use my script I had at the beginning of this thread to replace the string '£999' with 'OUT OF STOCK.

This is the script below but I just can't seem to get it to hit the right element. Ive tried elements such as form, input, select, attrib-12 (which is what my css is telling me) but none of them work..

<script language="javascript" type="text/javascript"> function replaceWord(control, oldWord, newWord) { var pageElement = document.getElementById(control); oldWord = new RegExp(oldWord, "g"); if (pageElement.value) pageElement.value = pageElement.value.replace(oldWord, newWord); else pageElement.innerHTML = pageElement.innerHTML.replace(oldWord, newWord); } </script> <div id="page"> <body onload="replaceWord('FORM', '+£999.00', 'Out Of Stock')" />
13 Mar 2012, 9:57 AM
#30
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

So Ive come back to this original thought, as on further thinking it really does have good uses.

Im fine on static titles, like category titles on a listing, or product titles and description on a product page, but when there is a listing with more than one product title or category title on a page (such as categories sidebox or a category listing lots of products, I get stuck.

If I do what ive been doing so far, I get one category in the side box to change its title, but then all the others vanish, like wise, I can get one product in a listing to change, and all the others vanish.

I assume because Im modifiying an array, and not a fixed string.

For example, in tpl_columnar display... I had a listing of 157 products, but this makes only one appear with the correct name, and the other 156 vanish off the page. Any ideas?

<?php // The text string $list_box_contents2[$row][$col] = $list_box_contents[$row][$col]; // The word we want to replace $oldWordprodtitle = "oldword"; // The new word we want in place of the old one $newWordprodtitle = "newword"; // Run through the text and replaces all occurrences of $oldText $list_box_contents2[$row][$col] = str_replace($oldWordprodtitle , $newWordprodtitle , $list_box_contents2[$row][$col]); ?> <?php /** * Common Template - tpl_columnar_display.php * * This file is used for generating tabular output where needed, based on the supplied array of table-cell contents. * * @package templateSystem * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: tpl_columnar_display.php 3157 2006-03-10 23:24:22Z drbyte $ */ ?> <?php if ($title) { ?> <?php echo $title; ?> <?php } ?> <?php if (is_array($list_box_contents) > 0 ) { for($row=0;$row<sizeof($list_box_contents);$row++) { $params = ""; //if (isset($list_box_contents[$row]['params'])) $params .= ' ' . $list_box_contents[$row]['params']; ?> <?php for($col=0;$col<sizeof($list_box_contents[$row]);$col++) { $r_params = ""; if (isset($list_box_contents[$row][$col]['params'])) $r_params .= ' ' . (string)$list_box_contents[$row][$col]['params']; if (isset($list_box_contents[$row][$col]['text'])) { ?>
<?php echo '<div' . $r_params . '>' . $list_box_contents2[$row][$col]['text'] .  '</div>' . "\n"; ?>
<?php } } ?> <br class="clearBoth" /> <?php } } ?>
13 Mar 2012, 12:27 PM
#31
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

Well Ive done it, Ive managed to do everything, including all the meta-tags on every page, category. The only thing im stuck on is alt tags for images and titles for images.

Does anyone know which file/module extracts the product title and converts it to an alt/title tag?

This is the original site

Dress Site 2

and this is the second duplicate with every occurrence of 'bodycon' converted in real time to 'going out'

Dress Site 2

Both sites use exactly the same database.

If you view source on each page you'll see all the meta tags have been converted too.

13 Mar 2012, 3:25 PM
#32
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Replacing a text string on a page

To be really clever you can use the javascript word replace script I posted on page 2, to turn the text back to the original wording, so the sites look no different to the user, but google only sees the new keyworded content - the only issue is the Javascript is triggered after the page is loaded so there is a lag in changing the text, and it slows the page load down.