我的英文写得不好。我使用joomla 2.5,我想转换为wprd按。
我为这个动作编写了一个插件,我能够传输内容和类别。
但是我无法将内容的图像从joomla转移到wp!这是我的代码:
<?php
require_once 'wp-blog-header.php';
require_once 'wp-admin/includes/taxonomy.php';
header('Content-Type: text/html; charset=UTF-8');
global $wpdb;
$wp_cat_id = array('11' => '74', '12' => '174', ....);
$con = mysql_connect("localhost", "....", "...") or die(mysql_error());
$db = mysql_select_db('tebroomc_tebnew');
mysql_query("set character_set_results='utf8'");
$result = mysql_query("SELECT * FROM `bme5k_categories` WHERE `parent_id` = 1 AND `level` = 1 AND `published` != -2 AND `metadesc` != ''") or die(mysql_error());
while ($root_cat = mysql_fetch_object($result)) {
$result2 = mysql_query("SELECT * FROM `bme5k_categories` WHERE `parent_id` =" . $root_cat->id . " AND `level` = 2 AND `published` != -2") or die(mysql_error());
$my_cat = $root_cat->id;
// $wp_root_cat_id = wp_insert_category($my_cat);
$root_cat_posts_sql = mysql_query("SELECT * FROM `bme5k_content` WHERE `catid` = " . $root_cat->id . " ") or die(mysql_error());
if (mysql_num_rows($root_cat_posts_sql) > 0) {
while ($posts = mysql_fetch_object($root_cat_posts_sql)) {
$my_post = array(
'post_title' => $posts->title,
'post_content' => $posts->introtext,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array($wp_cat_id[$my_cat]),
'post_date' =>$posts->publish_up
);
wp_insert_post($my_post);
}
}
while ($sub_cat = mysql_fetch_object($result2)) {
$my_cat = $sub_cat->id;
$sub_cat_posts_sql = mysql_query("SELECT * FROM `bme5k_content` WHERE `catid` = " . $sub_cat->id . " ") or die(mysql_error());
if (mysql_num_rows($sub_cat_posts_sql) > 0) {
while ($posts = mysql_fetch_object($sub_cat_posts_sql)) {
$my_post = array(
'post_title' => $posts->title,
'post_content' => $posts->introtext,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array($wp_cat_id[$my_cat]),
'post_date' =>$posts->publish_up
);
wp_insert_post($my_post);
}
}
}
}
我把这个代码在word press根站点。现在我想知道,当我从joomla读到一个内容,我已经把内容转移到word press,我怎么能得到那个帖子的图像?
这要看情况。通常Joomla不映射数据库中的图像,它们只是插入到标记中。如果你把/images文件夹复制到wordpress上,它们可能会马上工作。
然而,在#__content
表的images
字段中设置了一些图像是可能的,尽管这是J2.5中很少使用的特性,所以不太可能。无论如何,如果要使用它们,您仍然可以在/images文件夹中找到它们。
Joomla 2.5中字段的典型内容为:
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
为了读取它,只需用
创建一个对象$images = json_decode($posts->images)
则可以使用
$images->image_intro
等。