我正在使用论文,我正在使用下面的代码片段显示相关帖子。我的问题是,我不想在主页上加载相关帖子。有了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\');
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.