1

我目前一直在使用此代码根据与该帖子关联的标签为我的每个博客帖子输出相关帖子。

<?php

    $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'=>5, // Number of related posts that will be shown.
        'caller_get_posts'=>1
         );

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

    <div class="brelated">
        <?php get_the_image(array(
    'custom_key' => array('post_thumbnail','thumbnail'),
    'default_size' => 'thumbnail',
    'default_image' => $defthumb,
    'image_scan' => true,
    'image_class' => 'single',
)); ?>
<a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </div>
    <? }
       }
       }
    $post = $orig_post;
    wp_reset_query(); ?>
    </div>

但是,我想根据这些标签在我的多站点安装中包含来自另一个博客的相关帖子。

有什么方法可以使用类似的代码来使用 switch_to_blog() 函数来实现这一点。到目前为止,我几乎没有成功。我不是程序员,但我对 WordPress 代码的工作原理非常了解。

4

0 回答 0