获取没有echo的变量的文字值

时间:2011-12-19 21:41:38

标签: php wordpress

我有一个函数list_child_sibling_pages,当初始的2个if / ifelse语句为false时,它返回一个'hidden'字符串。

我需要将文字返回值'hidden'放入下面的数组中,如下所示

array('classname'=>'custom child-parent-menu-container'。$ hidden,'description'=>'自动将子页面菜单添加到父页面。自动将兄弟菜单添加到子页面');

我知道我可以用

输出它

echo list_child_sibling_pages();

但我不知道如何处理下面的代码。如果我只是在它上面回应它,那么这个值就可以了。我唯一的问题是在我需要的地方回应它

相关代码如下

function tmm_child_parent_menu(){

function list_child_sibling_pages()
{   
global $post;// if outside the loop
$post_type = '&post_type='.get_post_type(); 
$children = get_pages('child_of='.$post->ID.$post_type);
$parent_title = get_the_title($post->post_parent);
$parent_permalink = get_permalink($post->post_parent);
 
//child pages   
    if ( $post->post_parent && !is_search() && !is_404() ) 
    { ?> 
            <h4><?php echo '<a href="'.$parent_permalink.'">'.$parent_title.'</a>'; ?></h4>
            <ul class="parent-page-children">
            <?php wp_list_pages( 'title_li=&child_of='.$post->post_parent.'&sort_column=menu_order'.$post_type ); ?>
            </ul>
        <?php 
    } 

//parent pages
    elseif ( count( $children ) != 0 && !is_search() && !is_404() )
    { ?>
            <h4><?php the_title(); ?></h4>
            <ul class="parent-page-children">
            <?php wp_list_pages( 'title_li=&child_of='.$post->ID.'&sort_column=menu_order'.$post_type ); ?>
            </ul>
        <?php 
    } 
    else 
    {
        return 'hidden';
    }
}   

    $hidden = list_child_sibling_pages();
    /* Widget settings. */
    $widget_ops = array( 'classname' => 'custom child-parent-menu-container '. $hidden, 'description' => 'Automatically add a child page menu to parent pages. Automatically add a sibling menu to child pages' );

1 个答案:

答案 0 :(得分:0)

困惑,但我认为你想要

        $array=array('classname'=>'custom child-parent-menu-container '.list_child_sibling_pages(),
'description'=>'Automatically add a child page menu to parent pages. Automatically add a sibling menu to child pages');