サポート » テーマ » 海外テーマ NewsPeperでの一覧表示時、抜粋文字数

  • 現在、Newspeperという海外テーマを使いサイトを制作中です。
    このテーマで以下の問題が出ており、解決の糸口を探しています。

    各投稿の一覧にて本文を自動で抜粋してトップページにて表示している
    箇所があるのですが、英文はしっかり設定している文字数で表示されますが、
    日本語になると本文全てが表示されてしまいます。

    以下サイトのLIFESTYLEというブロックの様な感じになります。
    http://nocomplex.org/wp/

    WP Multibyte Patchとfunctions.phpとの設定等はネットで情報が得られる物は
    ほぼ試しましたが、まったく上手くいきませんでした。

    the_excerptに他のモジュールで設定された内容のものが表示されている様なのですが、
    知識不足で理解出来ておりません。
    (文字数は管理画面で設定でき、英文はその内容で表示されております。)

    おそらく該当の箇所が以下のソースになるかと思います。

    * returns a string containing the numbers of words or chars for the content
    *
    * @param $post_content – the content thats need to be cut
    * @param $limit – limit to cut
    * @param string $show_shortcodes – if shortcodes
    * @return string
    */
    static function excerpt($post_content, $limit, $show_shortcodes = ”) {
    //REMOVE shortscodes and tags
    if ($show_shortcodes == ”) {
    // strip_shortcodes(); this remove all shortcodes and we don’t use it, is nor ok to remove all shortcodes like dropcaps
    // this remove the caption from images
    $post_content = preg_replace(“/\[caption(.*)\[\/caption\]/i”, ”, $post_content);
    // this remove the shortcodes but leave the text from shortcodes
    $post_content = preg_replace(‘\[[^\]]*\]‘,”,$post_content);
    }

    $post_content = stripslashes(wp_filter_nohtml_kses($post_content));

    /*only for problems when you need to remove links from content; not 100% bullet prof
    $post_content = htmlentities($post_content, null, ‘utf-8’);
    $post_content = str_replace(” “, “”, $post_content);
    $post_content = html_entity_decode($post_content, null, ‘utf-8’);

    //$post_content = preg_replace(‘(((ht|f)tp(s?)\://){1}\S+)’,”,$post_content);//Radu A
    $pattern = “/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i”;//radu o
    $post_content = preg_replace($pattern,”,$post_content);*/

    // remove the youtube link from excerpt
    //$post_content = preg_replace(‘~(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@?&%=+\/\$_.-]*~i’, ”, $post_content);

    //excerpt for letters
    if (td_util::get_option(‘tds_excerpts_type’) == ‘letters’) {

    $ret_excerpt = mb_substr($post_content, 0, $limit);
    if (mb_strlen($post_content)>=$limit) {
    $ret_excerpt = $ret_excerpt.’…’;
    }

    //excerpt for words
    } else {
    /*removed and moved to check this first thing when reaches thsi function
    * if ($show_shortcodes == ”) {
    $post_content = preg_replace(‘\[[^\]]*\]‘,”,$post_content);
    }

    $post_content = stripslashes(wp_filter_nohtml_kses($post_content));*/

    $excerpt = explode(‘ ‘, $post_content, $limit);

    if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(” “,$excerpt).’…’;
    } else {
    $excerpt = implode(” “,$excerpt);
    }

    $excerpt = esc_attr(strip_tags($excerpt));

    if (trim($excerpt) == ‘…’) {
    return ”;
    }

    $ret_excerpt = $excerpt;
    }
    return $ret_excerpt;
    }

    もし解決のヒントをいただける様であれば
    ご回答宜しくお願い致します。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは、

    WP Multibyte Patchとfunctions.phpとの設定等はネットで情報が得られる物は
    ほぼ試しましたが、まったく上手くいきませんでした。

    大分苦労しているのだろうと推察しますが、一言でいうと 概要表示用のカスタム関数が

    「オレオレコード」で書かれているために、一般的な概要表示のカスタマイズ方法や、マルチバイトパッチのコントロールが効かない状態になっています。

    提示いただいた概要文用の関数には、ほとんどワードプレス関数は使われていませんし、標準的なフィルターやアクションも実装されていません。

    解決方法は、制作者のみぞ知るという状態に見えますので、テーマのサポートフォーラムで質問をしてみるのが最善です。

    static function excerpt($post_content, $limit, $show_shortcodes = '') {
       $limit = 40;//40文字で切りたい場合

    のように$limitの値を関数の中で強制的に指定してみたらどうでしょう。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「海外テーマ NewsPeperでの一覧表示時、抜粋文字数」には新たに返信することはできません。