开发者

Putting html within a php array [closed]

开发者 https://www.devze.com 2023-04-07 03:38 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I'm having problems with the syntax for a php array.

<?php
$pages = get_pages(array('child_of' => $post->ID, 'sort_column' => 'menu_order'));
$data = array();
foreach($pages as $post){
  setup_postdata($post);
  $fields = get_fields(); 
  $data[] = '<p>'.$fields->company_name.'</p><img src="'.$fields->company_logo."' />';
}
wp_reset_query();

// the js array
echo 'var marker_data =开发者_Go百科 ' . json_encode($data) . ';'; // Instead of implode
?>

Specifically this line:

$data[] = '<p>'.$fields->company_name.'</p><img src="'.$fields->company_logo."' />';

I'm getting all kinds of errors with adding the img tag, how would I format it correctly?


$data[] = '<p>' . $fields->company_name . '</p><img src="' . $fields->company_logo. '" />';

You just changed the '" to "' which was wrong :)


Change that line

$data[] = '<p>'.$fields->company_name.'</p><img src="'.$fields->company_logo."' />';

to

$data[] = '<p>'.$fields->company_name.'</p><img src="'.$fields->company_logo.'" />';

The problem is after the $fields->company_logo.

You have enter "' instead of '"

0

精彩评论

暂无评论...
验证码 换一张
取 消