drf21989 2012-01-13 01:25
浏览 51

调用wp-load.php从主站点上的Wordpress Blog加载3个最近的帖子,现在无法切换回其他数据库

I have a main site at www.mydomain.com. I have a wordpress blog set up at www.mydomain.com/blog. I want visitors to my main site to see the 3 recent blog posts. I was able to pull it off easily using the following code:

<?php    
define('WP_USE_THEMES', false);
require('/home/mydomain/public_html/blog/wp-load.php');
query_posts('showposts=3');
?>

<?php while (have_posts()) : the_post(); ?>
      <div class='category rounded_box'>
        <?php if ( get_post_meta($post->ID, 'image', true) ) { ?>
        <div class="category-thumbnail">
            <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&h=100&w=100&zc=1" width="100" height="100" border="0" /></a>
        </div>
        <?php } ?>
        <div class='category_title'>
            <h2><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></h2>
        </div>
        <div class='duration_home'>
            <?php the_excerpt(); ?>
            <span>Posted on <?php the_time('F jS, Y') ?> - <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></span>
        </div>
      </div>
      <?php endwhile;?>

<?php
wp_reset_query();
?>

Problem now is, anything on the page that requires calling a table for the main site no longer works. I'm getting an error saying it is searching for that table in the Wordpress blogs database.

How do I break the connection to the Wordpress database?

  • 写回答

2条回答 默认 最新

  • doujiang9887 2012-01-13 02:25
    关注

    I know you fixed your issue, however, for future reference you should define each connection object when working with multiple connections. If your main database is on the same mysql server then you should be able to do a mysql_select_db($dbname); after you run the wordpress code; instead of closing and reopening the connection. For multiple connections follow the information from this answer: How do you connect to multiple MySQL databases on a single webpage?

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题