亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        WordPress教程:相關(guān)文章中去除當前文章ID方法

        字號:


            通常我們的wordpress都是調(diào)用全站的相關(guān)文章,當然也會包括當前文章,如何才能調(diào)用相關(guān)文章的時候去除當前文章呢?方法并不難,在調(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), //去除當前文章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>隨機文章</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ù),不多做解釋,可以用也可以不用。