• I am changing a HTML site to wordpress. I used a switch case function to read the url and assign a variable if url contains a certain name. How can I do this in wordpress?

    So for example if the URL has cat the variable =cat.

    • This topic was modified 2 years, 8 months ago by Jan Dembowski.
Viewing 4 replies - 1 through 4 (of 4 total)
  • It will depend on how your URL’s are formatted. Are the variables part of the URL itself, eg:

    /page/var/cat

    Or are they added as standard URL values, eg:

    page/?var=cat

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    my old url was like site.com/section/page.php
    now with wordpress it is site.com/page

    I was using

    $currentFile = $_SERVER["SCRIPT_NAME"];
    		$parts = explode('/', $currentFile);
    		$currentFile = $parts[count($parts) - 1];
    		$parts = explode('.', $currentFile);
    		$currentFile = $parts[0];
    		switch ($currentFile)
    			{
    			case "index":

    If you want to get the last value, in your example that’s “page”, then it’s easy… a lot easier then you had it before.

    Something like this (untested, should work… not guaranteed):

    $parts = explode ('/', $_SERVER ['SCRIPT_NAME']);
    $currentFile = array_pop ($parts);
    
    switch ($currentFile) {
        case 'page':
            doSomething ();
            break;
    }
    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    I want to set $currentFile = the_title();

    But it’s not working.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Read URL’ is closed to new replies.