douxieqiu0651 2013-08-27 18:54
浏览 60

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

I need to create a XML with the content of an old site to import in Wordpress with oficial Wordpress Importer Plugin. Based on XML exported by Wordpress, I can create a compatible export export of my content. This export is like this example:

<?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 imports this well. Now I want to add a thumbnail to each post. I only find examples with the id of the image post ID, like these example:

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

Of course this do not work for me, because the content does not belong to another Wordpress site. How can I handle that? Is there any other way to import post thumbnail? Or there is another way to import posts for another non-Wordpress (nor non-Blogger/Drupal/Joomla) content?

  • 写回答

1条回答 默认 最新

  • dss67853 2013-12-06 16:22
    关注

    lets say you have the following in your post's import code:

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

    that usually means that this record of type post is referencing another record of type attachment, so lets say you have a post with id# 5 you need to add another item somewhere with <wp:post_type>attachment</wp:post_type> and a <wp:post_parent>5</wp:post_parent> like this:

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

    i hope this helps

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题