0

I want to include:

<?php the_field('200_200_1', 'option'); ?>

before the opening div tag in the line below...

$output .= '<div class="datebarcolor">'.$dates4.'</div>';

I am not sure how to insert the php tag in these circumstances. This is a php file, btw.

Can someone point me in the right direction?

4
  • 2
    Try include 'your_file_path.php'; at the point you need it. But I do not advice it in your case. Try learning about templating - have a google on it. Commented Jan 13, 2014 at 22:05
  • Why do you need to insert a PHP tag when PHP interpreter is running? Commented Jan 13, 2014 at 22:06
  • @EdHeal I think separation of concerns ?! Looks like it... Commented Jan 13, 2014 at 22:06
  • @MarkusHofmannn - I was assuming that the PHP tag was <?php? Am I wrong? Commented Jan 13, 2014 at 22:07

3 Answers 3

2

If you're using ACF in wordpress you can use get_field() over the_field() in order to store the output in your $output variable:

$output .= get_field('200_200_1', 'option');
$output .= '<div class="databarcolor">' . $date4 . '</div>';
Sign up to request clarification or add additional context in comments.

3 Comments

If this is the case, then this is a better way than doing it via output buffering. Edit: Apparently it is ;)
@Krister Sorry, one question. How would I add opening and closing div tags to get_field();?
@Desi - Something like $output .= '<div>'.get_field('200_200_1', 'option').'</div>'; perhaps?
0

If you want to include the output of some other PHP code (for instance, if the_field does some echo calls) and you want to add that to the $output variable, use ob_start and ob_get_clean, like so:

ob_start();
the_field('200_200_1', 'option');
$output .= ob_get_clean(); //This appends everything to $output that was echoed since the call to ob_start
$output .= '<div class="datebarcolor">'.$dates4.'</div>';

Comments

0

I think you either mean:

Include the file before executing this code:

include 'yourfile.php';

// ... some code ...
$output .= '<div class="datebarcolor">'.$dates4.'</div>';

or include the file and add it's output to $output:

// start output buffer
ob_start();
include 'yourfile.php';

// get buffer contents and clean the buffer
$output .= ob_get_clean();

$output .= '<div class="datebarcolor">'.$dates4.'</div>';

Comments

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.