简体   繁体   English

获取joomla发布图片

[英]get joomla post image

I can not write good English.I use joomla 2.5 and i want to convert to wprd press. 我不会写好英语。我使用的是joomla 2.5,我想转换为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 : 但是我无法将内容的图像从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);
            }
        }
    }
}

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 ? 我将此代码放在word press根站点中。现在我想知道,当我从joomla中读取内容并将内容转移到word word中时,如何获得该帖子的图像?

This really depends. 这真的取决于。 Usually Joomla does not map the images in the db, they are just inserted in the markup. 通常,Joomla不会在db中映射图像,它们只是插入标记中。 If you copy the /images folder over to wordpress, they may work right away. 如果将/ images文件夹复制到wordpress,它们可能会立即起作用。

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. 但是,有可能在#__content表的images字段中设置了一些图像,尽管它是J2.5上很少使用的功能,所以不太可能。 Anyway, should they be used, you will still find them in the /images folder. 无论如何,如果要使用它们,您仍然会在/ images文件夹中找到它们。

The typical content of the field in Joomla 2.5 is: Joomla 2.5中该字段的典型内容是:

{"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. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM