首页 文章

用于在Wordpress中导入内容的XML格式

提问于
浏览
1

我需要使用oficial Wordpress Importer Plugin在Wordpress中创建一个包含旧网站内容的XML . 基于XML exported by Wordpress,我可以创建我的内容的兼容导出导出 . 这个导出就像这个例子:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" ...>
<!-- xml header based on Wordpress export -->

<?php foreach($posts as $post): ?>
    <item>
        <title><?php echo $post['title']; ?></title>            
        <pubDate><?php echo date('r', strtotime($post['date'])); ?></pubDate>
        <dc:creator>admin</dc:creator>          
        <description></description>
        <content:encoded><![CDATA[<?php echo $post['content']; ?>]]></content:encoded>
        <excerpt:encoded><![CDATA[<?php echo $post['excerpt']; ?>]]></excerpt:encoded>          
        <wp:post_date><?php echo $post['date']; ?></wp:post_date>
        <wp:post_date_gmt><?php echo $post['date']; ?></wp:post_date_gmt>
        <wp:comment_status>open</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>           
        <wp:status>publish</wp:status>
        <wp:post_parent>0</wp:post_parent>
        <wp:menu_order>0</wp:menu_order>
        <wp:post_type>post</wp:post_type>
        <wp:post_password></wp:post_password>
        <wp:is_sticky>0</wp:is_sticky>
        <category><![CDATA[<?php echo $post['category']; ?>]]></category>
        <category domain="category" nicename="<?php echo StringToSlug::gen($post['category']); ?>"><![CDATA[<?php echo $post['category']; ?>]]></category>
        <wp:postmeta>
            <wp:meta_key>_edit_last</wp:meta_key>
            <wp:meta_value><![CDATA[1]]></wp:meta_value>
        </wp:postmeta>

    </item>
<?php endif; ?>

Wordpress很好地导入了这个 . 现在我想为每个帖子添加一个缩略图 . 我只找到带有图片帖子ID的id的示例,如下例所示:

<wp:postmeta>
    <wp:meta_key>_thumbnail_id</wp:meta_key>
    <wp:meta_value><![CDATA[43]]></wp:meta_value>
</wp:postmeta>

当然这对我不起作用,因为内容不属于另一个Wordpress网站 . 我该怎么处理?有没有其他方法导入后缩略图?或者还有另一种方法来导入另一个非Wordpress(也不是非Blogger / Drupal / Joomla)内容的帖子?

1 回答

  • 0

    假设您在帖子的导入代码中有以下内容:

    <wp:postmeta>
        <wp:meta_key>_thumbnail_id</wp:meta_key>
        <wp:meta_value><![CDATA[43]]></wp:meta_value>
    </wp:postmeta>
    

    这通常意味着这个类型post的记录引用了另一个类型附件的记录,所以假设你有一个id为# 5 的帖子你需要在 <wp:post_type>attachment</wp:post_type><wp:post_parent>5</wp:post_parent> 这样的地方添加另一个项目:

    <item>
        <title>imagefile1</title>
        <link>http://www.mysite.org/yourpostpermalink/attachment/imagefile1/</link>
        <pubDate>Fri, 06 Dec 2013 10:24:03 +0000</pubDate>
        <dc:creator>you</dc:creator>
        <guid isPermaLink="false">http://www.mysite.com/wp-content/uploads/imagefile1.png</guid>
        <description></description>
        <content:encoded><![CDATA[]]></content:encoded>
        <excerpt:encoded><![CDATA[]]></excerpt:encoded>
        <wp:post_id>43</wp:post_id>
        <wp:post_date>2013-12-06 11:24:03</wp:post_date>
        <wp:post_date_gmt>2013-12-06 11:24:03</wp:post_date_gmt>
        <wp:comment_status>closed</wp:comment_status>
        <wp:ping_status>open</wp:ping_status>
        <wp:post_name>imagefile1</wp:post_name>
        <wp:status>inherit</wp:status>
        <wp:post_parent>5</wp:post_parent>
        <wp:menu_order>0</wp:menu_order>
        <wp:post_type>attachment</wp:post_type>
        <wp:post_password></wp:post_password>
        <wp:is_sticky>0</wp:is_sticky>
        <wp:attachment_url>https://www.mysite.com/wp-content/uploads/imagefile1.png</wp:attachment_url>
        <wp:postmeta>
            <wp:meta_key>_wp_attached_file</wp:meta_key>
            <wp:meta_value><![CDATA[imagefile1.png]]></wp:meta_value>
        </wp:postmeta>
    
    </item>
    

    我希望这有帮助

相关问题