Hi David,
Hope you are well! In PTO 3.0 I would like to add a custom 'breadcrumb' in the Product page with links to category, brand and custom field(s).
I'm using the existing %DB_myfield% and added the code to be able to use %DBH_myfield% as a proper hyphenated url as described in https://www.pricetapestry.org/node/420.
WP code would be something like:
<p class="pto_pmr"><a href="/gender/%DBH_gender%/">%DB_gender%</a>
>
<a href="/brand/%DBH_brand%/">%DB_brand%</a></p>
Both %DB_myfield% are okay, but the DBH field is not recognized/declared. What am I doing wrong?
Hope you can help and thank you as always,
Marlies
Hi David,
I'm having a problem with the custom field in the breadcrumb on the productpage. So far I've got:
<p style="text-align:right;" class="pto_pmr">
%IF_DB_category%<a href='/c/%DBH_category%/'>%DB_category%</a> ▹ %ENDIF_DB_category%
%IF_DB_gender%<a href='/gender/%DBH_gender%/'>%DB_gender%</a> ▹ %ENDIF_DB_gender%
%IF_DB_brand%<a href='/merk/%DBH_brand%/'>%DB_brand%</a>%ENDIF_DB_brand%
</p>
Category & brand work fine, but the created url (Base href) for the custom field 'gender' isn't right and results in a 404.
{link saved}
When I change its settings to <a href='/shop?pto_q=gender:%DBH_gender%'>%DB_gender%</a>
the url is right, but then the IF-ENDIF statement is not recognized anymore (and I need it, because sometimes there is no gender available).
Hope you can help, thank you!
cheers, Marlies
Hello Marlies,
%IF_DB_field% and %ENDIF_DB_field% should be %ENDIFDB_field% and %ENDIFDB_field% - that should be all it is, have a go with:
<p style="text-align:right;" class="pto_pmr">
%IFDB_category%<a href='/c/%DBH_category%/'>%DB_category%</a> ▹ %ENDIFDB_category%
%IFDB_gender%<a href='/shop?pto_q=gender:%DBH_gender%'>%DB_gender%</a> ▹ %ENDIFDB_gender%
%IFDB_brand%<a href='/merk/%DBH_brand%/'>%DB_brand%</a>%ENDIFDB_brand%
</p>
Cheers,
David.
--
PriceTapestry.com
Hi David,
The %IFDB_field% and %ENDIFDB_field% are not recognized on the productpage and are printed as text in the breadcrumb.
I made the changes described on node 420 and also used the code submitted by george-p on Tue, 2014-10-14 17:21 on the end of the page and changed pto_product.php:
if (strpos($html_product,"%DB_"))
{
preg_match_all('/%DB_(.*)%/U',$html_product,$matches);
foreach($matches[1] as $field)
{
$html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
}
}
into
if (strpos($html_product,"%DB_"))
{
preg_match_all('/%DB_(.*)%/U',$html_product,$matches);
foreach($matches[1] as $field)
{
if ($product->$field)
{
$html_product = str_replace("%IF_DB_".$field."%","",$html_product);
$html_product = str_replace("%ENDIF_DB_".$field."%","",$html_product);
$html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
}
else
{
$html_product = str_replace("%DB_".$field."%","",$html_product);
$html_product = preg_replace('/%IF_DB_'.$field.'%(.*)%ENDIF_DB_'.$field.'%/U','',$html_product);
}
}
}
That's why I used the breadcrumb code with the _ which works with category, gender & brand, but stops being recognized when the link for gender is setup as '/shop?pto_q=gender:%DBH_gender%' instead of '/gender/%DBH_gender%/' that produces a non-existing url.
I made no further changes to pto_product.php except the ones on node 420 & this page.
Thanks,
Marlies
Hello Marlies,
Ah my apologies, when I implemented the IF/ENDIF support in version 3 I didn't incorporate the underscore so I just re-created my test using the code from above and it worked OK however I did notice that the modification to swap out %DBH_fieldname% with the hyphenated version was not present so I included this resulting in the following;
if (strpos($html_product,"%DB_"))
{
preg_match_all('/%DB_(.*)%/U',$html_product,$matches);
foreach($matches[1] as $field)
{
if ($product->$field)
{
$html_product = str_replace("%IF_DB_".$field."%","",$html_product);
$html_product = str_replace("%ENDIF_DB_".$field."%","",$html_product);
$html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);
$html_product = str_replace("%DBH_".$field."%",str_replace(" ","-",$product->$field),$html_product);
}
else
{
$html_product = str_replace("%DB_".$field."%","",$html_product);
$html_product = preg_replace('/%IF_DB_'.$field.'%(.*)%ENDIF_DB_'.$field.'%/U','',$html_product);
}
}
}
...and this seems to be working OK with or without gender using:
<p style="text-align:right;" class="pto_pmr">
%IF_DB_category%<a href='/c/%DBH_category%/'>%DB_category%</a> ▹ %ENDIF_DB_category%
%IF_DB_gender%<a href='/shop?pto_q=gender:%DBH_gender%'>%DB_gender%</a> ▹ %ENDIF_DB_gender%
%IF_DB_brand%<a href='/merk/%DBH_brand%/'>%DB_brand%</a>%ENDIF_DB_brand%
</p>
If you could perhaps check that combination (if not what's already in place) and if still no joy if you could email me your modified pto_product.php I'll check it out further with you...
Cheers,
David.
--
PriceTapestry.com
Great, it's working now!
Thank you so much for your support!
Marlies
Hello Marlies,
The modification from node 420 only applies to the Prices / Each template. To do the same for Product / Main edit pto_product.php and look for the following code at line 528:
$html .= $html_product;
...and REPLACE with:
if (strpos($html_product,"%DBH_"))
{
preg_match_all('/%DBH_(.*)%/U',$html_product,$matches);
foreach($matches[1] as $field)
{
$html_product = str_replace("%DBH_".$field."%",pto_common_hyphenate($product->$field),$html_product);
}
}
$html .= $html_product;
Your template code above should then work fine!
Cheers,
David.
--
PriceTapestry.com