2

I'm trying to get a specific page content from a page and i need to insert this php code:

i tried this:

$output .= <<<HTML

            </div>
        </div>
<div id="hometabs">
echo getPageContent(8);
    </div>
<div class="clear"></div>
    </div>

    <div class="bottom_shadow"></div>

</div>
HTML;

but it doesn't work.. i even tried:

getPageContent(8);
echo getPageContent(8)
<?php echo getPageContent(8);?>

still it didn't

note: i already have code for the getPageContent i'm just not sure why when viewing on my browser, this code: echo getPageContent(8) shows up instead of executing it.

1
  • 1
    This seems like more of a PHP related question than a Wordpress specific question. Commented Feb 15, 2012 at 2:23

1 Answer 1

3

The syntax you're using is called a Heredoc in PHP. It's a special way to build a string and put it into a variable but it allows you to have line breaks and quotes and other cool things (like using php variables inside the string).

Unfortunately you can't execute functions inside a heredoc unless you do some special and creative syntax changes to your code. Here's another SO question that is similar to what you're facing: Calling PHP functions within HEREDOC strings.

If I were doing this, I'd probably change the syntax up a bit like this (see if this works for you):

$the_content = getPageContent(8);

$output .= <<<HTML

        </div>
    </div>
    <div id="hometabs">
        $the_content
    </div>
    <div class="clear"></div>
    </div>

    <div class="bottom_shadow"></div>

    </div>
HTML;
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for letting me know it's heredoc. I didn't know that :) and it worked perfect too!

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.