質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

解決済

2回答

5730閲覧

Wordpress:カスタム投稿タイプで独自のいいねボタンを設置したい

shiro-kuma

総合スコア15

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

0クリップ

投稿2017/03/09 14:32

編集2017/03/10 11:16

###前提・実現したいこと
カスタム投稿タイプの各記事に、独自のいいねボタンを設置し、
運用後、記事ごと、ユーザーごとのいいね数をランキングにしたいと思っています。

###発生している問題・エラーメッセージ
様々なプラグインを試しましたが、一様に、
・カウントされない
・プラグイン内のCSSが反映されない
・プラグイン内の画像が表示されない
という問題に直面しています。

どのプラグインでも似たような現象なので、パスの問題なのかと考えていますが、どのあたりを修正すれば対応できるようになるでしょうか?
また、他に簡単に実装できるプラグインプラグインなどはございますでしょうか?
なにかヒントでも、ご教示いただけますと幸いです。

###該当のソースコード
functions.phpのphpのカスタム投稿タイプの設定は下記のように行っています。

PHP

1add_action( 'init', 'create_post_type' ); 2function create_post_type() { 3 register_post_type( 'news', 4 array( 5 'labels' => array( 6 'name' => __( 'ニュース' ), 7 'singular_name' => __( 'ニュース' ) 8 ), 9 'public' => true, 10 'has_archive' => true, 11 'rewrite' => true, 12 ) 13 ); 14 register_post_type( 'communications', 15 array( 16 'labels' => array( 17 'name' => __( '社内ブログ' ), 18 'singular_name' => __( '社内ブログ' ) 19 ), 20 'public' => true, 21 'has_archive' => true, 22 'rewrite' => true, 23 'supports' => array('title','editor','thumbnail','comments','author'), 24 'taxonomies' => array('communications_cat'), 25 ) 26 ); 27 register_taxonomy( 28 'communications_cat', //分類名 29 'communications', //タクソノミーを使う投稿タイプ名 30 array( //$args 31 'hierarchical' => true, 32 'label' => 'ブログのカテゴリ', 33 'show_ui' => true, 34 'query_var' => true, 35 'rewrite' => true, 36 'singular_label' => 'ブログのカテゴリ' 37 ) 38 ); 39} 40 41add_filter( 'post_type_link', 'my_post_type_link', 1, 2 ); 42function my_post_type_link( $link, $post ){ 43 if ( 'news' === $post->post_type ) { 44 return home_url( '/news/' . $post->ID ); 45 } else if ( 'communications' === $post->post_type ){ 46 return home_url( '/communications/' . $post->ID ); 47 } else { 48 return $link; 49 } 50} 51 52add_filter( 'rewrite_rules_array', 'my_rewrite_rules_array' ); 53function my_rewrite_rules_array( $rules ) { 54 $new_rules = array( 55 'news/([0-9]+)/?$' => 'index.php?post_type=news&p=$matches[1]', 56 'communications/([0-9]+)/?$' => 'index.php?post_type=communications&p=$matches[1]', 57 ); 58 59 return $new_rules + $rules; 60}

また、パーマリンク設定は下記です。

http://ドメイン/%post_id%/

このあたりが問題なのかと考えているのですが…

###試したこと
試したプラグインは下記になります。
WP Ulike
参考:https://clrmemory.com/wordpress/wpulike-goodbutton-plugin/

PHP

1<?php 2/* 3Plugin Name:WP ULike 4Plugin URI: http://preview.alimir.ir/developer/wp-ulike/ 5Description: WP ULike plugin allows to integrate a beautiful Ajax Like Button into your wordPress website to allow your visitors to like and unlike pages, posts, comments AND buddypress activities. Its very simple to use and supports many options. 6Version: 2.4.2 7Author: Ali Mirzaei 8Author URI: http://about.alimir.ir 9Text Domain: wp-ulike 10Domain Path: /lang/ 11License: GPL2 12*/ 13 14//Do not change this value 15define( 'WP_ULIKE_VERSION' , '2.4.2' ); 16define( 'WP_ULIKE_SLUG' , 'wp-ulike' ); 17define( 'WP_ULIKE_DB_VERSION' , '1.3' ); 18 19//Load Translations 20load_plugin_textdomain( WP_ULIKE_SLUG, false, dirname( plugin_basename( __FILE__ ) ) .'/lang/' ); 21 22/** 23 * When the plugin is activated, This function will install wp_ulike tables in database (If not exist table) 24 * 25 * @author Alimir 26 * @since 1.1 27 * @updated 1.7 28 * @return Void 29 */ 30register_activation_hook( __FILE__, 'wp_ulike_install' ); 31function wp_ulike_install() { 32 global $wpdb; 33 34 $table_name = $wpdb->prefix . "ulike"; 35 if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) { 36 $sql = "CREATE TABLE " . $table_name . " ( 37 `id` bigint(11) NOT NULL AUTO_INCREMENT, 38 `post_id` int(11) NOT NULL, 39 `date_time` datetime NOT NULL, 40 `ip` varchar(30) NOT NULL, 41 `user_id` int(11) NOT NULL, 42 `status` varchar(15) NOT NULL, 43 PRIMARY KEY (`id`) 44 );"; 45 46 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 47 dbDelta( $sql ); 48 49 add_option( 'wp_ulike_dbVersion', WP_ULIKE_DB_VERSION ); 50 } 51 52 $table_name_2 = $wpdb->prefix . "ulike_comments"; 53 if ( $wpdb->get_var( "show tables like '$table_name_2'" ) != $table_name_2 ) { 54 $sql = "CREATE TABLE " . $table_name_2 . " ( 55 `id` bigint(11) NOT NULL AUTO_INCREMENT, 56 `comment_id` int(11) NOT NULL, 57 `date_time` datetime NOT NULL, 58 `ip` varchar(30) NOT NULL, 59 `user_id` int(11) NOT NULL, 60 `status` varchar(15) NOT NULL, 61 PRIMARY KEY (`id`) 62 );"; 63 64 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 65 dbDelta( $sql ); 66 67 update_option( 'wp_ulike_dbVersion', WP_ULIKE_DB_VERSION ); 68 } 69 70 $table_name_3 = $wpdb->prefix . "ulike_activities"; 71 if ( $wpdb->get_var( "show tables like '$table_name_3'" ) != $table_name_3 ) { 72 $sql = "CREATE TABLE " . $table_name_3 . " ( 73 `id` bigint(11) NOT NULL AUTO_INCREMENT, 74 `activity_id` int(11) NOT NULL, 75 `date_time` datetime NOT NULL, 76 `ip` varchar(30) NOT NULL, 77 `user_id` int(11) NOT NULL, 78 `status` varchar(15) NOT NULL, 79 PRIMARY KEY (`id`) 80 );"; 81 82 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 83 dbDelta( $sql ); 84 85 update_option( 'wp_ulike_dbVersion', WP_ULIKE_DB_VERSION ); 86 } 87 88 $table_name_4 = $wpdb->prefix . "ulike_forums"; 89 if ( $wpdb->get_var( "show tables like '$table_name_4'" ) != $table_name_4 ) { 90 $sql = "CREATE TABLE " . $table_name_4 . " ( 91 `id` bigint(11) NOT NULL AUTO_INCREMENT, 92 `topic_id` int(11) NOT NULL, 93 `date_time` datetime NOT NULL, 94 `ip` varchar(30) NOT NULL, 95 `user_id` int(11) NOT NULL, 96 `status` varchar(15) NOT NULL, 97 PRIMARY KEY (`id`) 98 );"; 99 100 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 101 dbDelta( $sql ); 102 103 update_option( 'wp_ulike_dbVersion', WP_ULIKE_DB_VERSION ); 104 } 105 106} 107 108 109/** 110 * Applied to the list of links to display on the plugins page 111 * 112 * @author Alimir 113 * @since 2.3 114 * @return String 115 */ 116$prefix = is_network_admin() ? 'network_admin_' : ''; 117add_filter( "{$prefix}plugin_action_links", 'wp_ulike_add_plugin_links', 10, 5 ); 118function wp_ulike_add_plugin_links( $actions, $plugin_file ) 119{ 120 static $plugin; 121 122 if (!isset($plugin)) 123 $plugin = plugin_basename(__FILE__); 124 if ($plugin == $plugin_file) { 125 126 $settings = array('settings' => '<a href="admin.php?page=wp-ulike-settings">' . __('Settings', WP_ULIKE_SLUG) . '</a>'); 127 $stats = array('stats' => '<a href="admin.php?page=wp-ulike-statistics">' . __('Statistics', WP_ULIKE_SLUG) . '</a>'); 128 $about = array('about' => '<a href="admin.php?page=wp-ulike-about">' . __('About', WP_ULIKE_SLUG) . '</a>'); 129 130 $actions = array_merge($about, $actions); 131 $actions = array_merge($stats, $actions); 132 $actions = array_merge($settings, $actions); 133 134 } 135 136 return $actions; 137} 138 139/** 140 * Redirect to the "About WP ULike" page after plugin activation. 141 * 142 * @author Alimir 143 * @since 2.3 144 * @return Void 145 */ 146add_action( 'activated_plugin', 'wp_ulike_activation_redirect' ); 147function wp_ulike_activation_redirect( $plugin ) { 148 if( $plugin == plugin_basename( __FILE__ ) ) { 149 exit( wp_redirect( admin_url( 'admin.php?page=wp-ulike-about' ) ) ); 150 } 151} 152 153/** 154 * This hook is called once any activated plugins have been loaded. 155 * 156 * @author Alimir 157 * @since 1.7 158 * @return Void 159 */ 160add_action( 'plugins_loaded', 'wp_ulike_update_db_check' ); 161function wp_ulike_update_db_check() { 162 if ( get_site_option( 'wp_ulike_dbVersion' ) != WP_ULIKE_DB_VERSION ) { 163 wp_ulike_install(); 164 } 165} 166 167//Include plugin setting file 168include plugin_dir_path( __FILE__ ) . 'admin/admin.php'; 169 170//Include general functions 171include plugin_dir_path( __FILE__ ) . 'inc/wp-functions.php'; 172 173//Include plugin scripts 174include plugin_dir_path( __FILE__ ) . 'inc/wp-script.php'; 175 176//Load WP ULike functions 177include plugin_dir_path( __FILE__ ) . 'inc/wp-ulike.php'; 178

Reaction Buttons
参考:https://liginc.co.jp/programmer/archives/3497

Zilla likes
参考:http://www.nxworld.net/wordpress/wp-plugin-zillalikes.html

###補足情報(言語/FW/ツール等のバージョンなど)
Wordpress 4.7.2

###追記
single.phpにwp_head();を入れることで、cssは反映されるようになりました。
しかし、カウントはされないままです。
ただ、いいねボタンを押すと、下記のエラーが出ます。

Uncaught ReferenceError: toastr is not defined

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2017/03/11 04:23

(1)使用しているテーマはなんですか? (2)仕様テーマをTwentySixteenなどのWordPress標準テーマに変更した場合にも現象は再現しますか? (3)他のプラグインを無効化した場合にも現象は再現しますか?
shiro-kuma

2017/03/13 03:34

ご質問ありがとうございます。(1))テーマはオリジナルで一から制作したものです。(2)標準テーマに変更すると動作します。(3)再現します。
guest

回答2

0

(1)使用しているテーマはなんですか?
->テーマはオリジナルで一から制作したものです。
(2)仕様テーマをTwentySixteenなどのWordPress標準テーマに変更した場合にも現象は再現しますか?
->標準テーマに変更すると動作します。
(3)他のプラグインを無効化した場合にも現象は再現しますか?
->再現します。

以上の状況から、使用しているテーマに原因があるものと思われます。

テーマを作成した場合のチェックリストが以下にあるので、制作したテーマが適合しているか確認してみてはいかがでしょうか。
https://wpdocs.osdn.jp/%E3%83%86%E3%83%BC%E3%83%9E%E3%81%AE%E4%BD%9C%E6%88%90#.E3.83.86.E3.83.B3.E3.83.97.E3.83.AC.E3.83.BC.E3.83.88.E3.83.95.E3.82.A1.E3.82.A4.E3.83.AB.E3.81.AE.E3.83.81.E3.82.A7.E3.83.83.E3.82.AF.E3.83.AA.E3.82.B9.E3.83.88

作成したテーマを見ていないので、当方には確かなことは言えませんが、
なんとなく、wp_head()wp_footer()が適切な位置にないのではないかなと予想しますので、まずはそこから確認してみてください。

投稿2017/03/13 04:18

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

自己解決

WP Ulikeは使えませんでしたが、Reaction Buttonsは使用できましたのでそちらで制作を進めたいと思います。

投稿2017/03/14 04:36

shiro-kuma

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問