我创建了一个名为function
的{{1}},但遗憾的是portfolio
的{{1}}在html
的功能正常工作时无法显示。
code
{p}仅wordpress
显示function portfolio($id){
$output = "<ul class=\"recentWorks port\">";
if (have_posts()) : {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("&cat={echo $id;}&showposts=6&paged=$paged&order=ASC");
}
while(have_posts()) : the_post();
$output .= "<li>";
$output.= "<span>";
the_title();
$output .= "</span>";
$output .= "</li>";
endwhile;
endif;
$output .= "</ul>";
return $output;
}
the_title()
html
已全部消失。
答案 0 :(得分:1)
不要将HTML存储在$output
变量中,并在函数末尾返回变量,而是尝试根据需要打印HTML。例如
print "<span>";
the_title();
print "</span>";
原因是因为the_title();
正在立即打印,但您的HTML不是,它只是进入变量,并由函数返回。然后,调用函数将负责打印变量,此时它将在the_title();
答案 1 :(得分:0)
试试这个: -
while(have_posts()) : the_post();
$output .= "<li>";
$output.= "<span>";
$output .= the_title(); // edited this line
$output .= "</span>";
$output .= "</li>";
endwhile;
答案 2 :(得分:0)
试试这个:
function portfolio($id) {
$output = "<ul class=\"recentWorks port\">";
if (have_posts()) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("&cat={echo $id;}&showposts=6&paged=$paged&order=ASC");
while (have_posts()) {
$the_post = the_post();
$output .= "
<li>
<span>
$the_post
</span>
</li>";
}
}
$output .= "</ul>";
return $output;
}
答案 3 :(得分:-1)
使用此代码
function portfolio($id){
$output = '<ul class=\"recentWorks port\">';
if (have_posts()) : {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("&cat={$id}&showposts=6&paged=$paged&order=ASC");
}
while(have_posts()) : the_post();
$output .= '<li>';
$output.= '<span>';
the_title();
$output .= '</span>';
$output .= '</li>';
endwhile;
endif;
$output .= '</ul>';
return $output;
}