在WordPress文章正文中插入相关文章

  • A+
所属分类:Wordpress

1:打开WordPress主题中的single.php
在single.php中找到这行代码:



2:用下面的这段代码替换Step 1中的代码

", $content);
for ($i = 0; $i

ID);
if ($categories) {
echo '或许你会喜欢下面的这些文章:^_^';
echo '

    ';
    $category_ids = array();
    foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
    $args=array(
    'category__in' => $category_ids,
    'post__not_in' => array($post->ID),
    'showposts'=>3, // 显示相关文章的数量
    'caller_get_posts'=>1
    );

    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

  • ';
    }
    ?>

    ";
    } ?>

    3:适当的美化一下
    按照自己的主题自己美化/shui

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: