如何获得wordpress页面图标和永久链接标题

时间:2014-11-19 11:41:58

标签: php wordpress

你好evryone我是wordpress的新手。和m面临一个问题, 我想在页面中访问我的所有子页面标题及其图标图像(在页面图标中上传)。我也得到了页面的标题,但永久链接和图标图像很难得到我。 拜托...请帮助我。我的代码在这里

<div class="vwt_single_blog_box_tab">
<?php if ( is_page() ) { 
    if($post->post_parent)
    {       
            $id = $post->post_parent; 
    }
        else
    {
            $id = $post->ID; 
    }
     //$children = wp_list_pages('title_li=&child_of='.$id.'&echo=0');
    $args = array(
        'sort_order' => 'ASC',
        'sort_column' => 'post_title',
        'hierarchical' => 1,
        'exclude' => '',
        'include' => '',
        'meta_key' => '',
        'meta_value' => '',
        'authors' => '',
        'child_of' => 1,
        'parent' => $id,
        'exclude_tree' => '',
        'number' => '',
        'offset' => 0,
        'post_type' => 'page',
        'post_status' => 'publish'
    ); 
    $pages = get_pages($args);      

    ?>      
    <ul>
        <?php
        foreach($pages as $page)
        {           
        ?>
         <li>
        <div class="software-part">
            <div class="soft-part">
            <?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
            <h1><?php echo apply_filters( 'the_title', $page->post_title, $page->ID ); ?></h1>
            <?php echo apply_filters( 'the_content', $page->post_content ); ?>
                <div class="software-part-right">
                <h2><?php echo $page->post_title; ?></h2>
                </div>
                <p><?php $page->post_content = get_the_content();
                $page->post_content = strip_tags($page->post_content);
                    echo substr($page->post_content, 0, 100); ?>
                </p>
            </div>
        </div>
         </li>


        <?php
        }
        ?>  
   </ul>
    <?php
}
?>                


</div>   

`

谢谢。

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

<div class="vwt_single_blog_box_tab">
<?php if ( is_page() ) { 
    if($post->post_parent)
    {       
            $id = $post->post_parent; 
    }
        else
    {
            $id = $post->ID; 
    }
     //$children = wp_list_pages('title_li=&child_of='.$id.'&echo=0');
    $args = array(
        'sort_order' => 'ASC',
        'sort_column' => 'post_title',
        'hierarchical' => 1,
        'exclude' => '',
        'include' => '',
        'meta_key' => '',
        'meta_value' => '',
        'authors' => '',
        'child_of' => 1,
        'parent' => $id,
        'exclude_tree' => '',
        'number' => '',
        'offset' => 0,
        'post_type' => 'page',
        'post_status' => 'publish'
    ); 
    $pages = get_pages($args);      

    ?>      
    <ul>
        <?php
        foreach($pages as $page)
        {           
        ?>
         <li>
        <div class="software-part">
            <div class="soft-part">
            <?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
            <h1><a href="<?php echo get_permalink( $page->ID ); ?>"><?php echo get_the_title( $page->ID ); ?> </a></h1>
        </div>
         </li>


        <?php
        }
        ?>  
   </ul>
    <?php
}
?>                


</div>

你以错误的方式调用固定链接和标题。使用get_permalink()和标题get_the_title();

我测试了输出并且它正在工作。

PS - 没有Icon这样的东西。你想要的是一个缩略图,可以是特色图片。