1

我需要创建一个包含旧站点内容的 XML,以便使用官方Wordpress Importer Plugin导入 Wordpress 。基于Wordpress 导出的 XML,我可以创建我的内容的兼容导出导出。此导出类似于以下示例:

<?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 的示例,例如这些示例:

<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)内容导入帖子?

4

1 回答 1

0

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

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

这通常意味着这个帖子类型的记录正在引用另一个附件类型的记录,所以假设你有一个 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>

我希望这有帮助

于 2013-12-06T16:22:39.257 回答