Page 1 of 1

href Link within PHP Code

Posted: Thu Mar 17, 2011 6:04 am
by OnlineD
I am new to PHP code so not sure of the syntax I need to use here. I want to put a javascript history.back link where it says PUT BACK LINK HERE within the following bit of code

Code: Select all

<?php $homepage_page_name = get_option('bb_homepage_page_name'); if (is_front_page()) {if($homepage_page_name != NULL) {echo $homepage_page_name;} else {echo 'Welcome';}} else if (is_single()) {if (in_category('portfolio')) {echo "Portfolio";} else {echo "PUT BACK LINK HERE";}} else if (is_search()) {echo "Search";} else if (is_archive() || is_category()) {echo "Products";} else if(is_page_template('blog.php')) {if($headline_value != NULL) {echo $headline_value;} else {echo 'Blog';}} else {if(get_post_meta($post->ID, headline_value, true) != NULL){echo get_post_meta($post->ID, headline_value, true);} else {echo the_title();}} ?>

I have tried just putting in the html within the quotes but then get an error.

Re: href Link within PHP Code

Posted: Thu Mar 17, 2011 8:07 am
by internet-solution
what HTML did you put and what error did you get?

Re: href Link within PHP Code

Posted: Thu Mar 17, 2011 11:32 am
by social_experiment
The error is most likely a syntax error as a result of not escaping correctly. Add the code below where you have "put back link here" and see if it works. Hth

Code: Select all

"<a href=\"javascript:history.back()\" >Back</a>";
Edit : The weird character between javascript and history is a ':'

Re: href Link within PHP Code

Posted: Fri Mar 18, 2011 3:52 am
by OnlineD
Many thanks, this did the trick.