Last active
December 4, 2016 09:00
-
-
Save sokoljr/34e98a96af4d44c213be2167435100ce to your computer and use it in GitHub Desktop.
Конвектор ucoz на wp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getBlog() { | |
$data = file_get_contents('Z:\home\test2.ru\www\news.txt'); | |
$data = preg_split( "/[^\\\]\n/m" ,$data); | |
$n = 0; | |
foreach ($data as $post) | |
{ | |
if (!isset($post[1])) | |
break; | |
$n++; | |
$post = explode('|',$post); | |
switch ($post[1]) | |
{ | |
case 1: | |
$cat_id = 9; | |
break; | |
case 2: | |
$cat_id = 4; | |
break; | |
default: | |
$cat_id = 2; // задаём категорию по-умолчанию | |
} | |
if (strlen($post[3]) == 1) | |
$post[3] = '0'.$post[3]; | |
if (strlen($post[4]) == 1) | |
$post[4] = '0'.$post[4]; | |
$source = array( | |
'post_title' => $post[11], // заголовок материала. | |
'post_content' => $post[13], // message | |
'post_status' => 'publish', // статус (опубликовано) | |
'post_author' => 1, // id автора | |
'post_category' => array($cat_id), // массив id категорий, у нас категория только одна | |
'post_date' => $post[2].'-'.$post[3].'-'.$post[4], // дата публикации | |
'post_type' => 'post', // post type, у меня создан отдельный blog, у вас же скорее всего это значение будет post | |
); | |
$post_id = wp_insert_post($source); // функция добавления записи | |
} | |
echo $n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment