I have this code:
foreach ($ck as $k) {
if (substr ($k, 0, 1) == '_')
{ // skip keys starting with '_'
continue;
}
$cv = get_post_custom_values($k, $post_id ); //Array
foreach ($cv as $c) {
if (empty ($c))
{ // skip empty value
continue;
}
$format_c = $c;
print_r ('<div style="font-size: 14px;">'.$k .': '. $format_c . ' / </div>');
}
}
?>
but the result is like this:
something: result /
something: result /
something: result /
How can I change the code to have:
something: result / something: result / something: result /
Thanks!
A <div>
is a block level element. Use an inline element like <span>
instead.
foreach ($ck as $k) {
if (substr ($k, 0, 1) == '_')
{ // skip keys starting with '_'
continue;
}
$cv = get_post_custom_values($k, $post_id ); //Array
foreach ($cv as $c) {
if (empty ($c))
{ // skip empty value
continue;
}
$format_c = $c;
echo "<span style='font-size: 14px;'>$k: $format_c / </span><br/>";
}
}
?>
Also, I don't think print_r()
does what you think it does. echo
or print
are used to output text.
foreach ($ck as $k) {
if (substr ($k, 0, 1) == '_')
{ // skip keys starting with '_'
continue;
}
$cv = get_post_custom_values($k, $post_id ); //Array
echo '<div style="display: inline; font-size: 14px;">';
foreach ($cv as $c) {
if (empty ($c))
{ // skip empty value
continue;
}
$format_c = $c;
print_r ($k .': '. $format_c . ' /);
}echo '</div>';
}
?>