第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Wordpress 側(cè)邊欄上的子列表中的縮略圖圖像

Wordpress 側(cè)邊欄上的子列表中的縮略圖圖像

PHP
守候你守候我 2021-08-28 14:39:13
我正在嘗試在 WordPress 側(cè)邊欄列表的子列表中獲取縮略圖。我不知道如何集成縮略圖的代碼。請(qǐng)幫我。這是我的代碼如下:function wpb_list_child_pages(){  global $post;  if(is_page() && $post->post_parent)    $childpages=wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->post_parent.'&echo=0');  else    $childpages=wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'&echo=0');  if($childpages)    $string='<ul class="list-unstyled">'.$childpages.'</ul>';  return $string;}add_shortcode('wpb_childpages', 'wpb_list_child_pages');
查看完整描述

2 回答

?
拉丁的傳說(shuō)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以創(chuàng)建自定義查詢,并且在該查詢中您可以根據(jù)條件更改參數(shù)。在循環(huán)內(nèi),您可以the_post_thumbnail()用來(lái)顯示帖子的特色圖片。


function wpb_list_child_pages() {

    global $post;

    ob_start();


    $qargs = array(

        'posts_per_page' => 10,

        'post_type'      => 'page',

        'orderby'        => 'menu_order',

    );


    if ( is_page() && $post->post_parent ) {

        $qargs['post_parent'] = $post->post_parent;

    } else {

        $qargs['post_parent'] = $post->ID;

    }


    $the_query = new WP_Query( $qargs );

    ?>

    <?php if ( $the_query->have_posts() ) : ?>

        <ul class="list-unstyled">

        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

            <li>

                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                <?php if ( has_post_thumbnail( ) ) : ?>

                    <?php the_post_thumbnail( 'post-thumbnail' ); ?>

                <?php endif; ?>

            </li>

        <?php endwhile; ?>

        <?php wp_reset_postdata(); ?>

        </ul>

    <?php endif; ?>

    <?php

    $output = ob_get_contents();

    ob_end_clean();

    return $output;

}


add_shortcode( 'wpb_childpages', 'wpb_list_child_pages' );


查看完整回答
反對(duì) 回復(fù) 2021-08-28
?
翻翻過(guò)去那場(chǎng)雪

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊

最簡(jiǎn)單的方法是使用函數(shù)。編寫(xiě) WP_Query 以獲取子列表中的縮略圖圖像。它將作為 wp_list_pages 工作。


function wpb_list_child_pages() {


global $post;


if ( is_page() && $post->post_parent )

$child_pages_query_args = array(

    'post_type'   => 'page',

    'post_parent' => $post->post_parent ,

    'orderby'     => 'menu_order'

);

else

$child_pages_query_args = array(

    'post_type'   => 'page',

    'post_parent' => $post->ID,

    'orderby'     => 'menu_order'

);


$child_pages = new WP_Query( $child_pages_query_args );


if ( $child_pages->have_posts() ) :

?>

<ul class="child_page_row">

<?php 

while ( $child_pages->have_posts() ) : $child_pages->the_post();

    ?>

    <li>

        <a href="<?php the_permalink(); ?>">

        <?php if(has_post_thumbnail()): ?>

            <div class="child_page_thumb">

                <?php the_post_thumbnail(array(240, 240)); ?>

            </div>

            <?php endif; ?>

                <div class="child_page_name">

                <?php the_title(); ?>

                </div>

        </a>

    </li>

<?php

endwhile; 

?>

</ul>

<?php    

endif;


wp_reset_postdata();

}


add_shortcode('wpb_childpages', 'wpb_list_child_pages');


查看完整回答
反對(duì) 回復(fù) 2021-08-28
  • 2 回答
  • 0 關(guān)注
  • 142 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)