サポート » プラグイン » Yet Another Related Posts Pluginについて

  • conos

    (@conos)


    Yet Another Related Posts Pluginでカスタム投稿タイプで投稿している関連記事を表示したいと思い散々調べたのですが、なかなかそれらしい記事がなかったのと今後他の方にも役立つと思い質問させて頂きました。

    プラグインの公式を見ると通常のpost、page以外にもカスタム投稿、タクソノミーを対象にした関連記事を表示できることまでは分かりました。しかし、公式にのっているphpをどこに挿入したらいいのか分からず困っています。

    公式:http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/other_notes/

    yarpp_related(array(
        'post_type' => array('post', 'page', ...),
        'show_pass_post' => false, // show password-protected posts
        'past_only' => false, // show only posts which were published before the reference post
        'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
        'recent' => false, // to limit to entries published recently, set to something like '15 day', '20 week', or '12 month'.
    ); // third argument: (optional) true to echo the HTML block; false to return it

    以上、よろしくお願いします。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • 既に自己解決されているかもしれませんが、同じところで悩んだので他の方の参考になれば。

    結論から言うと、公式のPHPコードを任意の場所に記述することで動きますが、いくつかの修正が必要です。
    頭に<?php 、最後に;?>を付与することはもちろんですが、コード中の(…)となっている部分(2箇所)を削除しないとエラーになります。

    コードの中身はYARPPの設定ですので、日本語化された本体の設定を参考にするとわかるかと思いますが、少しだけ。

    カスタム投稿タイプを関連に加えたい場合は、2行目を
    ‘post_type’ => array(‘post’, ‘page’, ‘カスタム投稿タイプ名’),
    とすれば動きます。

    タクソノミーを加える場合は、
    ‘tax’ => array(
    ‘post_tag’ => 1,

    ‘タクソノミー名’ => 1,
    などと行を加えていくと良いかと。

    でも、このコードの凄いところは、本体とは別に設定が可能で、さらに
    ‘template’ => ,
    で、それぞれ別のテンプレートを適用できるところかもしれません。

    自分も同じところで悩んだんですが、結果カスタム投稿タイプの場合はうまく動かなかったです

    プラグインの公式
    http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/other_notes/を見ながら、以下のコードを書き加えたのですがなぜかダメでした

    yarpp_related(array(
        'post_type' => array('post', 'mycustompost'),
        'show_pass_post' => false, // show password-protected posts
        'past_only' => false, // show only posts which were published before the reference post
        'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
        'recent' => false, // to limit to entries published recently, set to something like '15 day', '20 week', or '12 month'.
    )); // third argument: (optional) true to echo the HTML block; false to return it

    2行目のmycustompostがカスタムポスト名で、上記のコードを追加したのですがダメでした。

    もしYet Another Related Posts Pluginを使って、カスタムポストで投稿した記事を関連記事として表示する方法をご存知の方がいたら、教えていただけるとうれしいです。

    テーマのテンプレートファイルの表示したい箇所に記述していますか?(YARPPのテンプレートファイルではありません。)
     

    yarpp_related(array(
    	'post_type' => array('post', 'mycustompost'),
    	'show_pass_post' => false, // show password-protected posts
    	'past_only' => false, // show only posts which were published before the reference post
    	// 任意のテンプレートを利用する場合指定
    	//'template' => 'yarpp-template-xxxxxx.php', // either the name of a file in your active theme or the boolean false to use the builtin template
    
    ));

     
    上記の通り、yarpp_related()のpast_onlyはfalseにしますが、関連記事 (YARPP) 設定の関連スコア設定で[過去の記事だけを表示]にはチェックを入れておく必要がありました。
    確認したバージョンは3.5.2b1です。

    popupさん、レスありがとうございます。

    >テーマのテンプレートファイルの表示したい箇所に記述していますか?
    >(YARPPのテンプレートファイルではありません。)

    YARPPのテンプレートファイルに記述していましたので、テーマのテンプレートファイルに下記のコードを記述したところカスタムポストタイプの関連記事が表示されるようになりました。

    yarpp_related(array(
    	'post_type' => array('post', 'mycustompost'),
    	'show_pass_post' => false, // show password-protected posts
    	'past_only' => false, // show only posts which were published before the reference post
    	// 任意のテンプレートを利用する場合指定
    	//'template' => 'yarpp-template-xxxxxx.php' // either the name of a file in your active theme or the boolean false to use the builtin template
    ));

    バージョン3.5.2b1で確認しました。教えていただきありがとうございました。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • トピック「Yet Another Related Posts Pluginについて」には新たに返信することはできません。