php函数:html没有显示

时间:2014-07-09 05:49:11

标签: php html wordpress

我创建了一个名为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已全部消失。

4 个答案:

答案 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;
} 

Codex - The Loop

答案 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;
          }