【问题标题】:XML format to import content in Wordpress在 Wordpress 中导入内容的 XML 格式
【发布时间】:2013-08-27 18:54:39
【问题描述】:

我需要创建一个包含旧网站内容的 XML,以便使用官方 Wordpress Importer Plugin 在 Wordpress 中导入。 基于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 的示例,例如这些示例:

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

【问题讨论】:

    标签: php xml wordpress


    【解决方案1】:

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

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

    这通常意味着这个帖子类型的记录引用了另一个附件类型的记录,所以假设你有一个 id# 5 的帖子,你需要在某处添加另一个带有 &lt;wp:post_type&gt;attachment&lt;/wp:post_type&gt; 的项目,并且像这样的&lt;wp:post_parent&gt;5&lt;/wp:post_parent&gt;:

    <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>
    

    希望对你有帮助

    【讨论】:

    • 这很有趣。我会尽快尝试的!谢谢!
    • 此外,您还需要将导入项目的附件排序在顶部和之后,这样缩略图将存在于新的 Wordpress 数据库中,并且可以在导入帖子时引用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多