Вордпресс и php - поясните момент пожалуйста

(Ответов: 1, Просмотров: 406)
  1. Banned
    • Регистрация: 26.05.2011
    • Сообщений: 380
    • Репутация: 34
    • Webmoney BL: ?
    Скажите пожалуйста, что в этом коде дописать, чтоб переводились тайтлы, а не только текст страницы. Сейчас оно работает так: переводится текст страницы, а заголовок остается на исходном языке. Помогите, буду очень признателен, если за деньги, то договоримся, очень нужно.
    <?php
    /*
    Plugin Name: fromKvantTranslater
    Plugin URI: http://localhost
    Description: Translate posts
    Version: 1.0.0
    Author: Kvant
    Author URI: http://localhost
    */

    /* Copyright 2012 December (email : kvaant {at} gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    */
    function kvant_add_admin_page()
    {
    add_options_page('ВыполнеРЅРёРµ перевода','ПерРводчик',8,translate_options,'k vant_options_page');
    }
    function kvant_options_page()
    {
    add_option('kvant_client_id','Не задано');
    add_option('kvant_client_secret','Не задано');

    //echo '<h2>Задайте настройки</h2>';
    //kvant_set_options();

    echo '<h2>Выполнить перевод</h2>';
    kvant_translate();
    }
    /*function kvant_set_options()
    {

    }*/
    function kvant_translate()
    {
    echo
    '<form name="translate_form" method="post" action="'.$_SERVER['PHP_SELF'].'?page=translate_options">
    <input type="submit" name="translate_button" value="Перевести"></form>';

    if(isset($_POST['translate_button']))
    {
    global $wpdb;
    $sql = 'SELECT ID,post_content FROM wp_posts';
    $result = $wpdb->get_results($sql, ARRAY_A);

    echo '<table cellpadding="0" cellspacing="0" style="text-align:center;margin-top:50px;width:98%;">
    <tr style="background-color: #ffffd9;">
    <th style="width:200px;padding:5px;">Отве т яндекса</th>
    <th style="width:100px;padding:5px;">ID</th>
    <th style="width:200px;padding:5px;">Запи сано в базу</th>
    <th style="width:200px;padding:5px;">Част ь перевода (300 символов)</th>
    </tr>';
    $wpdb->show_errors();

    $colorTB = 'background-color:#f0f3f6';

    foreach ($result as $cat)
    {
    $colorYA = 'color:#990000';
    $colorSV = 'color:#990000';



    $len = mb_strlen($cat['post_content'],'utf-8');
    $num = ceil($len/1500);
    $text = '';
    $ans = true;

    //Разбиваем по кускам и переводим
    for($i=0;$i<$num;$i++)
    {
    //Переводим
    $get= json_decode(file_get_contents('http://translate.yandex.net/api/v1/tr.json/translate?lang=ru-uk&text='.urlencode(substr($cat['post_content'],$i*1500,1500))));

    if($get->code == 200)
    {
    $text = $text.$get->text[0];
    }
    else
    {
    break;
    $ans = false;
    }
    }

    if($ans)
    {
    //Записываем в базу
    $my_post = array();
    $my_post['ID'] = $cat['ID'];
    $my_post['post_content'] = $text;

    // Обновляем данные в БД
    $up = wp_update_post($my_post);

    //Прверяем статус сохранения в базу
    if($up)
    {
    $up = 'Сохранено';
    $colorSV ='color:#009900';
    }
    else $up = 'Не сохранено';

    $colorYA ='color:#009900';
    }
    else
    {
    //Если сервер не ответил то не сохраняем в базу
    $up = 'Не сохранено';
    }


    echo '
    <tr style="'.$colorTB.'">
    <td style="padding:5px;'.$colorYA.'">'.$get->code.'</td>
    <td style="padding:5px;color:#0000ff;">'.$cat['ID'].'</td>
    <td style="padding:5px;'.$colorSV.'">'.$up.'</td>
    <td style="padding:5px;text-align:left;"><xmp style="margin:0;">'.substr($text,0,100).'</xmp><xmp style="margin:0;">'.substr($text,100,100).'</xmp><xmp style="margin:0;">'.substr($text,200,100).'</xmp></td>
    </tr>';
    if($colorTB == 'background-color:#f0f3f6') $colorTB = 'background-color:#f6f9fa';
    else $colorTB = 'background-color:#f0f3f6';
    }
    echo '</table>';
    }


    }
    add_action('admin_menu','kvant_add_admin_page')
    ?>
    • 0
  2. Sunshine reggae Аватар для OKyJIucT
    • Регистрация: 02.09.2011
    • Сообщений: 3,240
    • Репутация: 1830
    • Webmoney BL: ?
    romer, я так подозреваю, это не весь код. Для публикации кода используйте кнопки на панели инструментов (есть теги для Php кода), а особо большие полотна кода прячьте под спойлеры:)
    • 0

Похожие темы

Темы Раздел Ответов Последний пост
Поясните схему работы MS Office
Полезное ПО 11 01.04.2015 17:54
Поясните по Шаблону в Рапиде
PPC и контекстная реклама 4 26.05.2013 23:02
Поясните по Шаблону в Рапиде
Вопросы от новичков 0 20.03.2013 13:40
очень интересный момент с robotstxt в гугл
Общие вопросы поисковой оптимизации 3 11.09.2012 12:41
Поясните новичку про связи DNS-регистратора-хостинга
Хостинг и Серверы 2 27.01.2011 02:59

У кого попросить инвайт?

Вы можете попросить инвайт у любого модератора:

Информеры