使用 php 中的函数回显一堆 HTML 并使其具有如下内容是不好的做法:
function my_function() {
global $post;
$custom_fields = get_post_custom();
$some_field = $custom_fields ['some_field'][0];
?>
<div class="something <?php if ($some_field) { echo $special-clas;} ?>">
<div class="something-else">
/* bunch more of html code */
</div>
</div>
}
然后在你想用它来回显它的页面中?
<html>
<body>
.....
....
<?php echo my_function(); ?>
....
我不确定回显函数有多“被接受”?