все ок. вроде бы) PHP: include 'write_cache1.php'; foreach($aNews as $aItem){ $date = date("Y-m-d H:i:s", $aItem['date']); echo $aItem['type'] . ' ' . $aItem['text'] . $aItem['short_story'] . '<br>' . $date . '<br>'; } include 'read_cache1.php'; --- Добавлено --- Да все работает) --- Добавлено --- Будет время загляните) https://php.ru/forum/threads/shans-na-vypadenija-veschi.61627/
Поправил код. Хочу добавить новый параметр но он не берется..(TITLE) Код (PHP): <?php define ( 'DATALIFEENGINE', true ); //include($_SERVER['DOCUMENT_ROOT'] . '/engine/modules/functions.php'); include($_SERVER['DOCUMENT_ROOT'] . '/engine/api/api.class.php'); /* настройки */ $cat = '0,1,2,3,4,5,6'; // - категории новостей, через запятую $fields = 'date,short_story,title'; // перечень получаемых полей новостей или * для всех $start = '0'; // начальное значение выборки $limit = '5'; // количество новостей для выборки, 0 - выбрать все новости $sort = 'date'; // поле, по которому осуществляется сортировка $sort_order = 'desc'; // направление сортировки $length_text = '222'; // длина обрезания текста, оставляем без указания тект будет выводиться весь $row = $dle_api->take_news($cat, $fields,$start,$limit,$sort,$sort_order); $i = 0; $aDBNews = array(); while($row[$i] != "") { $title = $row[$i]['title']; $row[$i]['date'] = strtotime($row[$i]['date']); $aDBNews[] = $row[$i]; $i++; } $wall = file_get_contents("https://api.vk.com/method/wall.get?owner_id=-58395417&count=5&filter=owner&extended=1&v=5.62"); // Отправляем запрос $wall=json_decode($wall, true); $wall = $wall['response']['items']; $wall = array_map(function($aItem){ $aItem['type'] = 'VK'; return $aItem; }, $wall); $aDBNews= array_map(function($aItem){ $aItem['type'] = 'SITE'.var_dump($title).''; return $aItem; }, $aDBNews); $aNews=array_merge($aDBNews,$wall); usort($aNews, function($aItem1, $aItem2){ return (($aItem1['date'] < $aItem2['date']) ? 1 : (($aItem1['date'] == $aItem2['date']) ? 0 : -1)) ; }); //include 'write_cache.php'; foreach($aNews as $aItem){ $date = date("Y-m-d H:i:s", $aItem['date']); echo $aItem['type'] . ' ' . $aItem['text'] . $aItem['short_story'] . '<br>' . $date . '<br>'; } //include 'read_cache.php'; ?> Выводит NULL
мэн, нет желания разбираться как работает DataLife Engine, я щас на работе, и вечером буду работать, будет желание и время - помогу. И, пожалуйста, не стоит меня призывать, я не личный помощник
Если ты об этом куске PHP: while($row[$i] != "") { $title = $row[$i]['title']; $row[$i]['date'] = strtotime($row[$i]['date']); $aDBNews[] = $row[$i]; $i++; } то во-первых, если ты 10 раз перезапишешь переменную $title - её значение будет равным значению последней итерации, а во-вторых - скорее всего, нужно определиться с областью видимости этой переменной. Как я понимаю, ты к ней обращаешся здесь: PHP: $aDBNews= array_map(function($aItem){ $aItem['type'] = 'SITE'.var_dump($title).''; return $aItem; }, $aDBNews); А функция не видит просто так внешние переменные. Попробуй в начале ф-ции написать global ($title); P/S Если хочешь получить массив со значениями каждого $title замени в цикле $title = ... на $title[] = ...
Так? = Не работает Код (PHP): <?php define ( 'DATALIFEENGINE', true ); //include($_SERVER['DOCUMENT_ROOT'] . '/engine/modules/functions.php'); include($_SERVER['DOCUMENT_ROOT'] . '/engine/api/api.class.php'); /* настройки */ $cat = '0,1,2,3,4,5,6'; // - категории новостей, через запятую $fields = 'date,short_story,title'; // перечень получаемых полей новостей или * для всех $start = '0'; // начальное значение выборки $limit = '5'; // количество новостей для выборки, 0 - выбрать все новости $sort = 'date'; // поле, по которому осуществляется сортировка $sort_order = 'desc'; // направление сортировки $length_text = '222'; // длина обрезания текста, оставляем без указания тект будет выводиться весь $row = $dle_api->take_news($cat, $fields,$start,$limit,$sort,$sort_order); $i = 0; $aDBNews = array(); while($row[$i] != "") { $title[] = $row[$i]['title']; $row[$i]['date'] = strtotime($row[$i]['date']); $aDBNews[] = $row[$i]; $i++; } $wall = file_get_contents("https://api.vk.com/method/wall.get?owner_id=-58395417&count=5&filter=owner&extended=1&v=5.62"); // Отправляем запрос $wall=json_decode($wall, true); $wall = $wall['response']['items']; $wall = array_map(function($aItem){ $aItem['type'] = '/launcher/news/vk.png'; $aItem['title'] = 'ZOOMCRAFT – Майнкрафт сервера! ©'; return $aItem; }, $wall); $aDBNews= array_map(function($aItem){ $aItem['type'] = '/launcher/news/site.png'; $aItem['title'] = $title; return $aItem; }, $aDBNews); $aNews=array_merge($aDBNews,$wall); usort($aNews, function($aItem1, $aItem2){ return (($aItem1['date'] < $aItem2['date']) ? 1 : (($aItem1['date'] == $aItem2['date']) ? 0 : -1)) ; }); //include 'write_cache.php'; echo ' <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="/launcher/news/style.css"> <link rel="stylesheet" href="/launcher/news/jquery.mCustomScrollbar.css"> </head> <style> *{ margin: 0px; padding: 0px; font-family: Helvetica; } ::-webkit-scrollbar-track { background-color:#fff; } body{ background: url("/launcher/news/bg.png") no-repeat fixed; } table td{ vertical-align: top; } .name{ font-size: 15px; color: #fff; margin-top: 7px; } .text{ margin: 0 7px; color: #fff; font-size: 16px; } </style> <body>'; foreach($aNews as $aItem){ $monthes = array( 1 => 'Января', 2 => 'Февраля', 3 => 'Марта', 4 => 'Апреля', 5 => 'Мая', 6 => 'Июня', 7 => 'Июля', 8 => 'Августа', 9 => 'Сентября', 10 => 'Октября', 11 => 'Ноября', 12 => 'Декабря' ); $date = (date('d ', $aItem['date']) . $monthes[(date('n', $aItem['date']))] . date(' Y в H:i', $aItem['date'])); echo ' <table width="510px" border="0"> <tr> <td width="64px" style="padding-left: 7px;"> <img src="'.$aItem['type'].'" width="50px" height="50px"> </td> <td width="446px"> <div class="name">'.$aItem['title'].'<br/> '.$date.'</div> </td> </tr> <tr> <td colspan="2"> <div class="text"> '. $aItem['text'] . $aItem['short_story'].' </div> <center><hr style="width: 90%; height: 0.5px; background: #fff; margin: 10px 0;"></center> </td> </tr> </table> '; //echo $aItem['type'] . ' ' . $aItem['text'] . $aItem['short_story'] . '<br>' . $date . '<br>'; } echo ' <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="/launcher/news/jquery.mCustomScrollbar.concat.min.js"></script> <script> (function($){ $(window).load(function(){ $("body").mCustomScrollbar({ theme:"minimal-dark" }); }); })(jQuery); </script> </body> </html>'; //include 'read_cache.php'; ?>
Стоп, так а зачем ты вообще создаёшь эту переменную? Сделай так: aItem[$i]['title'] = $row[$i]['title']; Там же где инициализируешь этот $title. --- Добавлено --- А потом выводи в цикле.
Актуально. Выводит не нужную картинку. Как ограничить вывод картинок в новости? Пример: HTML: <p><img src=\"http://zoomcraft.ru/uploads/posts/2017-04/1492341391_bez_imeni-2_1_.jpg\" alt=\"\" width=\"1280\" height=\"720\" /></p>