chris86 Posted January 20, 2007 Share Posted January 20, 2007 I am trying to add an external link (i.e. a link to Google) into a forum sidebar. Unfortunately, I am getting a 404 error. The PHP code (which I was given) is appending my external URL to index.php (community) and then to the categories subdirectory. When the sidebar URL is clicked, the user should be directed to Google.com (in this example). But, instead of going to google.com, the user is directed to domain.com/community/categories/\"http://google.com"which produces a 404 error. Not good.Here's the code...[code]<?phpif(in_array($Context->SelfUrl, array("index.php", "categories.php", "discussions.php", "comments.php", "search.php", "post.php", "account.php", "settings.php"))){$content = <<< ENDCODE<br><strong> <font size=\"2"> My Heading Here </strong></font> <br><a href=\"http://google.com"> Google</a><br><a href=\"http://yahoo.com"> Yahoo</a>ENDCODE;$Panel->AddString($content,150);}?>[/code]I think it's the "SelfUrl, array" part of the code that's screwing up my external link. But, I am very new to PHP and don't fully understand the code above. And, what the heck is <<< ENDCODE ? Why three opening brackets? I have never seen this before. I just want to create a functioning external link. Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 20, 2007 Author Share Posted January 20, 2007 I got rid of the array part, and now I'm getting a parse error, which reads...Parse error: syntax error, unexpected '<' in /home/user_name/public_html/community/extensions/Sidepanel-2006-07-24/default.php on line 13Apparently, PHP doesn't like the beginning HTML tag.Here is my code:[code]<?phpif(isset($Panel)) <br><strong> <font size=\"2"> My Heading Here </strong></font> <br><a href=\"http://lussumo.com"> Lussumo</a><br><a href=\"http://google.com"> Google</a>');?>[/code]How do I get rid of the parse error? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 You can't just put HTML in PHP. You have to either print or echo it, or close your php.[code]<?phpif(isset($Panel)) {?><br><strong> <font size="2"> My Heading Here </strong></font> <br><a href="http://lussumo.com"> Lussumo</a><br><a href="http://google.com"> Google</a>');<?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 20, 2007 Author Share Posted January 20, 2007 Thanks Jesirose. That did the trick! The only problem now is that my links are sitting at the very top of the sidepanel. How do I move the links further down the page? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 With HTML. Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 20, 2007 Author Share Posted January 20, 2007 I tried adding a bunch of HTML break tags, and that doesn't work with the way this particular forum is set up. It just adds a bunch of white space, and pushes the discussion threads further down. I would like to add...[code]$Panel->AddString($content,150);[/code]back into to my code (Problem is, I don't have a string any longer). I think the "150" relates to where the content is positioned on the page. When I add that line of code back, I get an "undefined variable" error (because $content is undefined). How do I define the link data (anchor text and URL's) as $content ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 How do you think? Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 20, 2007 Author Share Posted January 20, 2007 $content= But how does that work with HTML code? I can’t do [code]$content= <br><strong> <font size="2"> My Heading Here </strong></font> <br><a href="http://lussumo.com"> Lussumo</a><br><a href="http://google.com"> Google</a>[/code]or I’m going to get another parse error. Quote Link to comment Share on other sites More sharing options...
Crimpage Posted January 20, 2007 Share Posted January 20, 2007 You need to escape the "'s with \'s[code]$content= "<br><strong> <font size=\"2\"> My Heading Here </strong></font> <br><a href=\"http://lussumo.com\"> Lussumo</a><br><a href=\"http://google.com\"> Google</a>";Enclosing all of that in " "'s tells php that it is a string and it doesnt care how it looks with <> or whatever. Without them, php wont like it.Dave[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 Since there are no variables, in the string, you should use single quotes, and then you don't have to escape anything.$content= '<br><strong> <font size="2"> My Heading Here </strong></font> <br><a href="http://lussumo.com"> Lussumo</a><br><a href="http://google.com"> Google</a>';I think you need to read up on basic code. Like, what strings, variables, functions ARE. Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 20, 2007 Author Share Posted January 20, 2007 Thank you Dave and Jesi. Yes, Jesi I am very new to PHP, and I could use a good book or two. I am open to any suggestions/recommendations.Ok, here is my new code...[code]<?php$content= '<br><strong> <font size="2"> My Heading Here </strong></font> <br><a href="http://lussumo.com"> Lussumo</a><br><a href="http://google.com"> Google</a>';if(isset($Panel))$Panel->$content; /* I want to display $content here. Is what I've written accurate? Is the arrow appropriate here? I tried searching Google for "arrow PHP" but I didn't find anything. I also tried searching for " -> PHP" but no luck. What do you call the arrow symbol? It's not an operator. */ ?>[/code]When I upload this code, I get [u]another[/u] error message. It says "Undefined property" on line 18. Line 18 is $Panel->$content. What have I done wrong? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 The -> is a call to a function or variable in an object. change $content to content.What is $Panel? If you're working with a third party script, you should check for support from them before randomly trying to call functions. If that's the way you display content in this class, then okay, but that's not a function so I doubt it will work. Quote Link to comment Share on other sites More sharing options...
chris86 Posted January 21, 2007 Author Share Posted January 21, 2007 Thanks Jesi. I figured it out with the help of some folks who know the forum software very well. Here's the code I ended up using:[code]<?phpif(in_array($Context->SelfUrl, array("index.php", "categories.php", "discussions.php", "comments.php", "search.php", "post.php", "account.php", "settings.php"))){$ListName = 'Recommended Resources';$Panel->AddList($ListName, 100);$Panel->AddListItem($ListName, '<font color="#0000ff"> Heading Title Here</font>', 'http://domain1.com');$Panel->AddListItem($ListName, '<font color="#0000ff">Heading Title 2 Here</font>', 'http://domain2.com'); }?>[/code]Everything's working great now. Thanks again for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.