href Link within PHP Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OnlineD
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 5:54 am

href Link within PHP Code

Post 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.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: href Link within PHP Code

Post by internet-solution »

what HTML did you put and what error did you get?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: href Link within PHP Code

Post 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 ':'
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
OnlineD
Forum Newbie
Posts: 5
Joined: Thu Mar 17, 2011 5:54 am

Re: href Link within PHP Code

Post by OnlineD »

Many thanks, this did the trick.
Post Reply