开发者

how to stop PHP variable being printed

I have this function I created to give my wordpress site a body tag...

   function give_body_class( $print = true )
{
    global $wp_query;
    $c = "";

    // Generic semantic classes for what type of content is displayed

    is_archive()        ? $c = 'archive_page'       : null;
    is_date()           ? $c = 'date_page'          : null;
    is_search()         ? $c = 'search_page'        : null;
    is_paged()          ? $c = 'paged_page'         : null;
    is_tree(2)      ? $c = 'type_1'         : null;         
    is_tree(42)     ? $c = 'type_2'         : null;         
    is_tree(55)     ? $c = 'type_3'                 : null;             
    is_tree(57)     ? $c = 'type_4'                 : null;                 
    is_home()           ? $c = 'front'                  : null; 
    is_404()            ? $c = 'error_404'              : nul开发者_运维知识库l; 

    return $print ? print($c) : $c;
}

I use this to print out the body class name in the header which is why I'm telling it to print.

And I am also trying use a logical statement on another page which is working, however I'm not sure how to stop it printing the variable.

e.g

<?php if (give_body_class('type_1')) { echo 'active'; } ?>

returns:

"type_1active"


Do you understand what parameters the function takes ?? It's only a boolean which determine if it must print the class or not, just pass false to not print !


Just change the last line to

return $c;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜