Viewing 12 replies - 1 through 12 (of 12 total)
  • A little more information about what you are going to do and exactly what you have done would be necessary to answer your question. The few characters of code you have shown so far are at least syntactically correct.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    The problem is that it is printing the title to the screen in addition to storing it in the variable.

    I am trying to run custom code for a page using a switch statement. I used the url before for my html site and not trying to do the same thing for wordpress. I’m trying the title now.

    Please show us the code you wrote for this.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

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

    That is never completely there. Furthermore, you can’t see in which context you are executing the code. So you can’t tell what you are doing wrong.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    This code is checking if the current url contain “location.”

    And where is it executed? Via a hook? In a template? Where? More info please so that your question can be answered.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    The array produced with $_SERVER[“SCRIPT_NAME”]; is only giving two pieces of information.
    parts[0] index
    part[1] php

    I need specific information such as the page title. but when i use the_title(); it just prints it to the screen.

    Then try https://developer.www.ads-software.com/reference/functions/get_the_title/ instead. Since I still can’t see the connection, I don’t know if that’s what you’re looking for.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    it is returning the title f the post. However I just want the first work of the post title.

    I assume you mean word instead of work. You can determine this with PHP:

    $words = explode(' ',trim(get_the_title()));
    $content = $words[0];

    Untested.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    Thanks! it worked.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘PHP Variables’ is closed to new replies.