我不会写好英语。我使用joomla 2.5,我想转换为wprd press。
我为此操作编写了一个插件,我能够传输内容和类别。
但是我无法将内容的图像从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 root site.Now我想知道,当我从joomla读取内容并将内容转移到word press时,我怎样才能获得该帖子的图像?
答案 0 :(得分:0)
这实际上取决于。 通常Joomla不会映射数据库中的图像,它们只是插入标记中。 如果将/ images文件夹复制到wordpress,它们可能会立即生效。
然而,在images
表的#__content
字段中可能会设置一些图像,尽管它在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
等