karisumasaking48
フォーラムへの返信
-
フォーラム: 使い方全般
返信が含まれるトピック: phpの中でbloginfo('template_url')が使えないget_template_directory_uriできました!
記述でエラーがでていたので記述ミスと思いテンプレートタグに問題があるとは思ってもいませんでした。
ありがとうございます。
フォーラム: 使い方全般
返信が含まれるトピック: jQueryでサイドバー追尾させる記述gatespace様
ありがとうございます。
知りたいことを調べて色々組み合わせてみたら解決いたしました。
色々とありがとうございます。フォーラム: 使い方全般
返信が含まれるトピック: archiveのフィルターフックについてHinaloe様
毎度のこと、ありがとうございます。
フォーラム: 使い方全般
返信が含まれるトピック: archiveのフィルターフックについてgblsm様
kjmtsh様ありがとうございます。
ちなみにですが、WordPressフィルター一覧的なものがあればリンク先などを教えて頂けたら助かります。
フォーラム: 使い方全般
返信が含まれるトピック: comment_author_link()を使った条件分岐Hinaloe様
毎回ありがとうございます。
echo内だけでなくif内もget_comment_author_link()、とのことですが
echo内で使用しているのはget_comment_author_url()になります。下記記述でうまく反映されましたが気になったので(^^;
<?php
if(get_comment_author_url()) {
echo ‘ <a href=” ‘ . get_comment_author_url() . ‘ “> ‘ . get_avatar( $comment -> comment_author_email, 65 ) . ‘ </a>’;
} else {
echo get_avatar( $comment -> comment_author_email, 65 );
}
?>感謝です!
getを忘れないようにしないといけませんね。
フォーラム: 使い方全般
返信が含まれるトピック: the_category()で特定のカテゴリーのみ非表示にさせたい回答ありがとうございます。
リンクを出力するというのは
<?php
$str = ”;
foreach(get_the_category() as $cat){
if($cat->term_id!==1):
$str .= $cat->cat_name . ‘・’;
endif;
}
echo rtrim($str, “・”);の中のget_the_category()をthe_category()にするということですよね?
それをすると下記のようなエラーがでます。
Warning: Invalid argument supplied for foreach() in /home/サーバID/ドメイン/public_html/wp-content/themes/テーマ名/single.php on line 66
フォーラム: 使い方全般
返信が含まれるトピック: global宣言が無効になっているKUCKLUさん
php…奥が深いですね(*´ー`*)
ありがとうございます!!!フォーラム: 使い方全般
返信が含まれるトピック: 関数を2つ以上使った変数同士の計算はできない?return…
phpだけで4冊の本を買い、そこそこの勉強はしてきたつもりですがreturnは使ったことがありませんでした。
とても助かりました。
ありがとうございます!
フォーラム: 使い方全般
返信が含まれるトピック: global宣言が無効になっている回答ありがとうございます。
実はまだ作成中の関数があるのです。
//—————————————————————————
// SNSのシェア数を取得
//—————————————————————————
//●twitter
function tw_count() {
$url = get_permalink();
$json = @file_get_contents(‘http://urls.api.twitter.com/1/urls/count.json?url=’ .$url. ”);
$array = json_decode($json,true);
$tw_count = $array[‘count’];
echo $tw_count;
}
add_shortcode(‘tw_count’, ‘tw_count’);//●Facebook
function fb_count() {
$url = get_permalink();
$json = @file_get_contents(‘http://graph.facebook.com/?id=’ . $url . ”);
$array = json_decode($json,true);
if(!isset($array[‘shares’])){
$count = 0;
}else{
$count = $array[‘shares’];
}
$fb_count = $count;
echo $fb_count;
}
add_shortcode(‘fb_count’, ‘fb_count’);//●hatena
function hb_count() {
$url = get_permalink();
$count = @file_get_contents(‘http://api.b.st-hatena.com/entry.count?url=’ . $url . ”);
if(!isset($count) || !$count){
$count = 0;
}
$hb_count = $count;
echo $hb_count;
}
add_shortcode(‘hb_count’, ‘hb_count’);//●Google+
function gp_count() {
$url = get_permalink();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, “https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ” );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_POSTFIELDS, ‘[{“method”:”pos.plusones.get”,”id”:”p”,”params”:{“nolog”:true,”id”:”‘ . $url . ‘”,”source”:”widget”,”userId”:”@viewer”,”groupId”:”@self”},”jsonrpc”:”2.0″,”key”:”p”,”apiVersion”:”v1″}]’ );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( ‘Content-type: application/json’ ) );
$result = curl_exec( $ch );
curl_close( $ch );
$obj = json_decode( $result, true );
if(!isset($obj[0][‘result’][‘metadata’][‘globalCounts’][‘count’])){
$count = 0;
}else{
$count = $obj[0][‘result’][‘metadata’][‘globalCounts’][‘count’];
}
$gp_count = $count;
echo $gp_count;
}
add_shortcode(‘gp_count’, ‘gp_count’);//●Feedly
//注) get_bloginfo(‘rss2_url’)はリンクエンドに/を含まない
function fl_count() {
$feed = rawurlencode(get_bloginfo(‘rss2_url’));
$json = @file_get_contents(“http://cloud.feedly.com/v3/feeds/feed%2F{$feed}”);
$obj = json_decode($json,true);
if(isset($obj[‘subscribers’])){
$fl_count = $obj[‘subscribers’];
}else{
$fl_count = 0;
}
echo $fl_count;
}
add_shortcode(‘fl_count’, ‘fl_count’);//●Youtube
function yt_count() {
$channel = ‘あなたのyoutubeチャンネル名に書き換えてください’;
$json = @file_get_contents(“http://gdata.youtube.com/feeds/api/users/{$channel}?alt=json”);
$obj = json_decode($json,true);
$yt_count = $obj[‘entry’][‘yt$statistics’][‘subscriberCount’];
echo $yt_count;
}
add_shortcode(‘yt_count’, ‘yt_count’);//●Linkedin
function li_count() {
$url = get_permalink();
$json = @file_get_contents(‘http://www.linkedin.com/countserv/count/share?url=’ .$url. ”);
$json = rtrim($json,’);’);
$json = ltrim($json,’IN.Tags.Share.handleCount(‘);
$array = json_decode($json,true);
$li_count = $array[‘count’];
echo $li_count;
}
add_shortcode(‘li_count’, ‘li_count’);KUCKLUさんが回答して頂いた記述が理解できれば、ほかのものも作り変えることも可能なのですが、私はまだその領域に達していないので少々難しいようです。。。
ちなみに上記関数を作成した上で
<?ぴーえいちぴー tw_count() ?>
などと個別に表示させることはもちろん
<?ぴーえいちぴー
$all_count = tw_count() + fb_count() + hb_count() + gp_count()
if($all_count >= 200) {
echo ‘認定記事’
}
?>というように指定した任意の数をシェア数が上回ったら色々したいのですが、
<?php
$all_count = tw_count() + fb_count();
echo $all_count ;
?>とか
<?php
$tw_count = tw_count();
$fb_count = fb_count();
$all_count = ( $tw_count + $fb_count );
?>とかいろいろ試しているのですが計算されずに文字列の足し算みたいな出力になっているのでそこで苦戦しています。
動作確認用の記事です。
http://amami-city.xsrv.jp/ozin/%E3%83%86%E3%82%B9%E3%83%88%E8%A8%98%E4%BA%8B-11-2-2-2-2-2-2-2-2-2-2-2-2-2関数はなんとなく分かってきたというレベルですので(*´ー`*)
関数なんか作らずに全部、index.phpで記述するならできますが、あまり記述を増やしたくないので、できればfanctions.php内で関数として定義付けて呼び出すという形で記述を減らしたいのです。
独自関数を作る前はSNS Count Cacheという各SNSのシェア数を取得し任意の指定した場所に表示してくれるプラグインがあるのですが、もしこのプラグインが廃止や停止になった場合、このプラグインに属するphp記述をしていた時はサイトがエラーを返すので、それならいっそのことシェア数取得する関数作ってしまえとう経緯からです(*´ー`*)
フォーラム: 使い方全般
返信が含まれるトピック: SNSシェア数取得でthe_permalink()がうまく反映されないgatespaceさん
ありがとうございます。
無事に解決でき、とても助かりました。フォーラム: 使い方全般
返信が含まれるトピック: 親カテゴリーではなく、先祖カテゴリーの取得方法回答ありがとうございます。
考え方はわかるのですが、肝心の記述がわからないため、質問させていただいています。
<?php
$cat = get_the_category();
$cat = $cat[0];$parent = get_category($cat->category_parent);
$parents = $parent->category_parent;
$parent_catname = $parents->cat_name;echo $parents_catname;
?>みたいな感じだとは思うのですが...。