在Wordpress外部切换Wordpress数据库

时间:2016-11-27 09:54:40

标签: wordpress

我在同一个域/服务器上有两个Wordpress博客 - 一个定期发布其他视频 - 加上其他非Wordpress页面,其中包含使用此代码的最新博客文章的框:

<ul>
<?php 
    require($_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php');
    $args = array(
        'cat' => 5, // Only source posts from a specific category
        'posts_per_page' => 1 // Specify how many posts you'd like to display
    );
    $latest_posts = new WP_Query( $args );  
    if ( $latest_posts->have_posts() ) {
        while ( $latest_posts->have_posts() ) {
            $latest_posts->the_post(); ?>
    <li>
        <span class="post_title"><?php the_title(); ?></span>
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
    <?php if ( has_post_thumbnail() ) { ?>
            <span class="post_thumbnail"><?php the_post_thumbnail(); ?></span>
    <?php } ?>
        </a>
        <span class="post_excerpt"><?php the_excerpt(); ?></span>
    </li>   
<? } 
    }
    wp_reset_postdata();
?>
</ul>

一切都按我的意愿行事。但是,我们现在想要在同一页面上的第一个框下面有第二个框,其中包含来自其他博客(视频)的帖子。由于wp-load.php已被包含在第一个博客框中,因此它会从错误的博客中获取帖子。

如何将数据库连接交换为其他(视频)博客的设置?

我搜索了解决方案并找到了

$wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );

我迷失了如何使用它并让它发挥作用。

我考虑将它们合并到一个博客中,但对于看似简单的问题而言似乎有些过分,所以不愿意这样做。

由于

0 个答案:

没有答案