duanguilin2007 2014-11-19 11:41
浏览 27
已采纳

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

hello evryone i am new on wordpress. and m facing a problem that, i want to access all my child page title and their icon image (which are uploaded in page icon) in a page. i also get the title of pages but permalink and icon image is hard to get me. please... please help me.my code is here

<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>   

`

thank you.

  • 写回答

1条回答 默认 最新

  • doulou0882 2014-11-19 11:59
    关注

    This should do the trick:

    <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>
    

    You were calling the permalink and title in the wrong way. For that use get_permalink() and for title get_the_title();

    I've tested the output and it's working.

    PS - There's no such thing as Icon. What you want is a thumbnail that can be a featured image or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog