0

www.mysite.com/?q=portraits#

I want a span within my menu to display the current section (ie. portraits)

I'm sure this is simple. Your help is much appreciated!

2 Answers 2

0

it's been a long time since i've used php, but the the variable you are referring to is what's known as a query string parameter, which is passed as a $_GET array in php. you can access the specific variable by using a string indexer of the array. in your markup:

<span><?php echo $_GET["q"]; ?></span>
Sign up to request clarification or add additional context in comments.

4 Comments

Mr. Nicksta this seems like the easiest answer but will it work if the page I have that on isn't php? My index is a php just so i can use the get command.
maybe i'm not understanding your question then? where does that link come from? you have an <a> tag on your page with that as the href? oh and no, it won't work without PHP, is there any reason why you can't/won't use php for subsequent pages?
nah. i suppose there isn't a reason. it'd probably allow me to do more things. will .php pages run just the same as html? js functions styling and all?
if you're going to require dynamic behaviour on your site, as described here, it's worthwhile just using php on every page. everything works exactly as normal, html, css, js, apart from what is inside the <?php ... ?> blocks - that is where you put your functionality and logic
0

You'll probably have to use javascript, if you're not working with PHP or something like that.

How to extract the get-query with javascript is explained here: How can I get query string values in JavaScript?

Then you can fork the result and add/remove content to/from the element you want to manipulate.

5 Comments

Quasdunk... I'm not sure exactly how to implement the code since there is a find function included in that script (i'm not fluent in scripting at all :( ) the index is a php file so i could use the get function... but all the subsequent pages are html
@rootsup Are they really HTML or are the extensions just rewritten (e.g. by the .htaccess)? Are they called directly or are they just being included? If they're just part of a template, you can use PHP in them. Otherwise it might be wiser and much easier renaming them to .php.
alright, I think I might use the code specified by nicksta and just rename everything to .php! Thanks for your time
@rootsup Yep, that should be the best solution. There won't be any disadvantages, you can run regular html and js code in there, the only difference is, that you can also use PHP additionally.
You could probably answer > stackoverflow.com/questions/6934021/… for me real quickly? It's my last question as my site is really simple

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.