I can not write good English.I use joomla 2.5 and i want to convert to wprd press.
I Writing a plugin for this action and I was able to transfer the content and the categories.
But i can not transfer image of content from joomla to wp!this is my code :
<?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);
}
}
}
}
I put this code in word press root site.Now I want to know,when i read a content from joomla and i have transfer the content into the word press,how can i get image of that post ?
This really depends. Usually Joomla does not map the images in the db, they are just inserted in the markup. If you copy the /images folder over to wordpress, they may work right away.
It is however possible that in the images
field of the #__content
table some images are set, although it was a feature hardly ever used on J2.5 so it's unlikely. Anyway, should they be used, you will still find them in the /images folder.
The typical content of the field in Joomla 2.5 is:
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
In order to read it, simply create an object with
$images = json_decode($posts->images)
then you can use
$images->image_intro
etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.