Where did they go from here プラグイン

Where did they go from here プラグインは、「この記事を読んだ方は、他にこんな記事を読んでいます。」を実現する WordPressのプラグインです。

そのページを訪問した人が、次にクリックしたページをトラッキングします。

プラグインページはこちら。
Where did they go from here

ページに表示するには、次の方法があります。

  1. 自動表示
    プラグインを有効化すると、コンテンツの後ろに自動挿入します。
    設定画面で表示するページ(投稿タイプなど)を選択します。
    設定画面では、サムネイル表示や表示したくないページなどの設定ができます。

  2. ショートコード
    ショートコード[wherego]
    

    設定画面で表示するページを選択せず、コーディングできるようfunctionも用意されています。

    phpif ( function_exists( 'echo_wherego' ) ) { echo_wherego(); }
    
  3. ウィジェット
    管理画面→外観→ウィジェット
    表示するページ数、サムネイル表示有無・表示位置、サムネイルサイズを設定できます。

※ちなみに、コンテンツに関連する投稿を表示するプラグインは、こちら。
Yet Another Related Posts Plugin (YARPP)
Contextual Related Posts
など

スタイルシート(css)

■表示されるリスト表示(ul)のラップ(div)
・コンテンツの後ろに表示
class="wherego_related"
・ウィジェット
class="wherego_related_widget"

■サムネイル
class="wherego_thumb"

■タイトル
class="wherego_title"

■抜粋
class="wherego_excerpt"

プラグイン設定ページ(管理画面→設定→WZ Followed Posts→Stylesタブ)でカスタムCSSをセットできるようにしたっぽいのですが、できないので、手を加えます。。。
ちょうどフィルターが用意されていました。

function.phpadd_filter(	'wherego_settings_styles', function( $custom_css ){
  $custom_css = array(
//変更  'custom_CSS' => array(
//変更    'id' => 'custom_CSS',
    'custom_css' => array(
      'id' => 'custom_css',
      'name' => esc_html__( 'Custom CSS', 'where-did-they-go-from-here' ),
/* translators: 1: Opening a tag, 2: Closing a tag, 3: Opening code tage, 4. Closing code tag. */
      'desc'  => sprintf( esc_html__( 'Do not include %3$sstyle%4$s tags. Check out the %1$sFAQ%2$s for available CSS classes to style.', 'where-did-they-go-from-here' ), '<a href="//wordpress.org/plugins/where-did-they-go-from-here/faq/' ) . '" target="_blank" rel="noopener">', '</a>', '<code>', '</code>' ),
      'type' => 'textarea',
      'options' => '',
    ),
  );
  return $custom_css;
} );

スタイルシートをセットするテキストエリアのnameとプラグインのオプション変数が、custom_css や custom_CSS で混在しているので、小文字に統一しました。
バージョンアップで、混在してしまったのかなと。

フィルター、アクション

カスタマイズしやすいよう、多くのフィルターが用意されています。ソース必見!

functions.php// リストをラップするdivのclass(デフォルト:wherego_related)を変更する
add_filter( 'wherego_post_class', function( $post_classes ){
  $post_classes = "my-related";
  return $post_classes;
} );

(追記)
バージョン2.1.0で、管理画面での設定をフィルターwherego_get_settingsでもセットできるようにしたっぽいのですが、
apply_filter の場所がいまいちで、セットできず…

幸いglobal変数にしているので、こんな感じでセットしてみます。

functions.phpなどadd_action( 'init', function(){
  global  $wherego_settings;
  $wherego_settings["title"] = "<h3>他にこな記事も読まれています。</h3>";
} );

これで、管理画面で操作しなくても、同じ設定を再現しやすくなりました!

PHP Noticeなど、気になる場合

管理画面→プラグイン一覧 のWhere did they go from hereプラグインのSettingsをクリックすると
「このページにアクセスする権限がありません。」
となりアクセスできません。。。

設定画面のリンクを修正します。

where-did-they-go-from-here/include/admin/admin.php LINE 201//変更前
'settings' => '<a href="' . admin_url( 'options-general.php?page=wherego_options' ) . '">' . esc_html__( 'Settings', 'where-did-they-go-from-here' ) . '</a>',

//変更後
'settings' => '<a href="' . admin_url( 'options-general.php?page=wherego_options_page' ) . '">' . esc_html__( 'Settings', 'where-did-they-go-from-here' ) . '</a>',

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です