如何从主页上删除相关帖子

时间:2015-07-23 作者:Sanjay Nakate

我正在使用论文,我正在使用下面的代码片段显示相关帖子。我的问题是,我不想在主页上加载相关帖子。有了css技巧,我们可以让它显示无,但它加载,所以我不想在主页上加载相关帖子。

我试过这个条件if ( is_home() )is_front_page() 加载特定页面的函数,但它会加载主页上的相关帖子。

有谁能告诉我如何防止这个钩子在没有css技巧的情况下卸载主页上的相关帖子。

function my_related_posts() {

 $orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
\'tag__in\' => $tag_ids,
\'post__not_in\' => array($post->ID),
\'posts_per_page\'=>12, // Number of related posts that will be shown.
\'caller_get_posts\'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {

echo \'<div id="related_posts"><h3 class="heading033">Read More</h3><ul>\';

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

<li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"> <?php echo the_post_thumbnail(\'medium\') ?></a></div>
<div class="relatedcontent">
<h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>

</div>
</li>
<? }
echo \'</ul></div>\';
}
}
$post = $orig_post;
wp_reset_query();

}
add_action(\'thesis_hook_after_post\',\'my_related_posts\');

1 个回复
SO网友:Mayeenul Islam

Simply

if(!is_home() && !is_front_page()) add_action( \'thesis_hook_after_post\', \'my_related_posts\' );

will do that for you. It will not do the add_action() when we are at the home page or not any front page.

If it doesn\'t work for you, may be you need to contact with the Thesis team.

结束

相关推荐

$wpdb returns duplicate posts

我创建了一个短代码,显示用户上次登录后创建的帖子。这个短代码工作得很好,但我不知道为什么,但我得到了7个重复的帖子。就像测试一样,我创建了一个名为“示例文章”的帖子,当我呼出帖子的标题时,我得到了这个结果。Sample Article Sample Article Sample Article Sample Article Sample Article Sample Article Sample Article Sample ArticleShortcodefunction latest_posts_af