午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    WordPress教程:相關(guān)文章中去除當(dāng)前文章ID方法
    來源:易賢網(wǎng) 閱讀:900 次 日期:2014-09-02 15:26:58
    溫馨提示:易賢網(wǎng)小編為您整理了“WordPress教程:相關(guān)文章中去除當(dāng)前文章ID方法”,方便廣大網(wǎng)友查閱!

    通常我們的wordpress都是調(diào)用全站的相關(guān)文章,當(dāng)然也會包括當(dāng)前文章,如何才能調(diào)用相關(guān)文章的時候去除當(dāng)前文章呢?方法并不難,在調(diào)用函數(shù)里添加一句 post__not_in 即可實現(xiàn),這個函數(shù)不要做太多解釋,按字面就可以理解了。

    具體實施方法如下:

    <?php

    $backup = $post;

    $tags = wp_get_post_tags($post->ID);

    $tagIDs = array();

    if ($tags) {

    $tagcount = count($tags);

    for ($i = 0; $i < $tagcount; $i++) {

    $tagIDs[$i] = $tags[$i]->term_id;

    }

    $args=array(

    ‘tag__in’ => $tagIDs,

    ‘post__not_in’ => array($post->ID), //去除當(dāng)前文章ID

    ‘showposts’ =>10,

    ‘caller_get_posts’=>1

    );

    $my_query = new WP_Query($args); ?>

    <div>

    <div>相關(guān)文章</div>

    <ul>

    <?php if( $my_query->have_posts() ) {

    while ($my_query->have_posts()) : $my_query->the_post(); ?>

    <li><a href=”<?php the_permalink() ?>” rel=”bookmark” target=”_self” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

    <?php endwhile;

    } else { ?>

    <?php $recent=new WP_Query( “showposts=10&caller_get_posts=1&orderby=rand”); while($recent->have_posts()) : $recent->the_post();?>

    <li><a href=”<?php the_permalink() ?>” rel=”bookmark” target=”_self” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

    <?php endwhile;    ?>

    <?php } ?>

    </ul>

    </div>

    <?php } else { ?>

    <div>

    <div>隨機(jī)文章</div>

    <ul>

    <?php $recent=new WP_Query( “showposts=10&caller_get_posts=1&orderby=rand”); while($recent->have_posts()) : $recent->the_post();?>

    <li><a href=”<?php the_permalink() ?>” rel=”bookmark” target=”_self” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

    <?php endwhile;    ?>

    </ul>

    </div>

    <?php } ?>

    <?php $post = $backup; wp_reset_query(); ?>

    這里我還用到了 wp_reset_query() ,這個是重置函數(shù),不多做解釋,可以用也可以不用。

    更多信息請查看IT技術(shù)專欄

    更多信息請查看CMS教程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:WordPress教程:相關(guān)文章中去除當(dāng)前文章ID方法
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
    相關(guān)閱讀CMS教程

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機(jī)號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)