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 '"
精彩评论