如何从Wordpress解析XML文件以在另一个CMS中使用?

问题描述 投票:-1回答:1

我发现这样做的资源很少。我正在使用MODX作为CMS,并希望从Wordpress获取我现有的博客并在新的CMS中使用它们。从MODX到WP的资源非常丰富,但是只有一种已发布的WP to MODX方法,using the Articles method,遗憾的是它不再起作用了。是否因为文章尚未更新或WP中的XML文件不兼容。

无论如何,我现在离开时试图用老式的方式做这件事,我将无法逐一介绍每篇文章。我想学习如何从WP获取导出的XML文件并将其解析为MODX,可能使用PHP。但我不确定从哪里开始。

任何建议都会有所帮助......是的,我已经尝试了Google。我不知道该从什么开始。

谢谢!

php xml wordpress parsing modx
1个回答
0
投票

getFeed代码段在这里有用。您可以使用它的代码,修改一下并处理WP提要项,如下所示:

if (!empty($url) && $modx->getService('rss', 'xmlrss.modRSSParser')) {
    $rss = $modx->rss->parse($url);
    if (!empty($rss) && isset($rss->items)) {
        while (list($itemKey, $item) = each($rss->items)) {
            foreach ($item as $k => $v) {
                $item[$k] = str_replace(array('[',']'),array('[',']'),$item[$k]);
            }
            /// process rss items here  
            // f.e. add new modx resources
            $newArticle = $this->modx->newObject('modResource'); //new article
            $newArticle->set( 'template', ARTICLE_TEMPLATE_ID ); // replace ARTICLE_TEMPLATE_ID with actual article template id
            $newArticle->set( 'pagetitle', $item['title'] ); // pagetitle
            $newArticle->set( 'parent', ARTICLE_CONTAINTER_ID);
            $newArticle->set( 'content', $item['description'] );

            //add other valuable fields

            if(!$newArticle->save()){
                // modx error
            }

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.