サイトのコード(一部)。_は/に読み替え。テストサイトは間に合いませんでした。稼働しているサイトは秘密。
<?php
function schema_markup($schema,$canonical,$ttitle,$s_schema){
return '<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "'.$schema.'",
"url": "'.$canonical.'",
"name": "'.$ttitle.'",
"publisher":{
"@context": "http://schema.org",
"@type": "Person",
"name": "'.get_the_author_meta('display_name',WP_ADMIN_ID).'",
"memberOf":{
"@context": "http://schema.org",
"@type": "MusicGroup",
"name": "'.get_bloginfo('name').'"
}
}'.$s_schema.'
}
</script>';
}
<?php
function jquery_man() {
//register_script();
wp_deregister_script('jquery');
wp_enqueue_script('prefixfree','https://cdn.jsdelivr.net/prefixfree/1.0.7/prefixfree.min.js');//header
wp_enqueue_script('mjquery','http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js','','',true);
wp_enqueue_script('mbootstrap','http://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js','','',true);
if(is_page('1441')){wpcf7_enqueue_scripts();}
if(!is_page()){
wp_deregister_script('jquery-form'); //contact-form-7
wp_deregister_script('contact-form-7');
}
if(!is_singular()){wp_deregister_script('toc-front');}
//下のは実装したい
//wp_enqueue_script('contextmenu','https://cdnjs.cloudflare.com/ajax/libs/bootstrap-contextmenu/0.3.4/bootstrap-contextmenu.min.js','','',true);
}
add_action('wp_enqueue_scripts', 'jquery_man');
?>
<?php
//Google Analyticsのデータから人気記事一覧を作成する
$thisfunc = 'popular';
require_once(dirname(__FILE__).'/token.php');
if($client->getAccessToken()){
try{
$start_date = date('Y-m-d', strtotime("-10 day", time())); // 10日前から
$end_date = date('Y-m-d', strtotime("today", time())); // 今日まで
$metrics = 'ga:pageviews';
$optParams = array(
'dimensions' => 'ga:pagePath',
'sort' => '-ga:pageviews',
'filters' => null,
'max-results' => 30 // 取得数
);
$data = $service->data_ga->get(GOOGLE_ANALYTICS_PROFILE_ID, $start_date, $end_date, $metrics, $optParams);
$results = array();
foreach($data['rows'] as $row => $value) {
foreach($data['columnHeaders'] as $key => $header) {
$results[$row][$header['name']] = $value[$key];
}
}
$html = '<div class="list-group">';
$popular_count = 1;
$lists = array();
foreach($results as $result){
if($popular_count > 5){break;}
// TODO ごちゃごちゃしているのでどうにかする
$post_url = site_url().$result['ga:pagePath'];
$post_id = url_to_postid($post_url); // URLから記事のIDを取得
$posttype = get_post_type($post_id);
if($post_id == 0 || $posttype == 'page' || in_array($post_id,$lists)){continue;}
array_push($lists,$post_id);
$img = post_main_img($post_id,null,'medium',false);
$html .= post_list_small($post_id,'PopularPosts','this.href',$img);
//IDさえあれば他の所では概要とれてるのに此処で取れないのなんでだろう(あとまわし)
++$popular_count;
}
$html .= '</div>';
$file_path = dirname(__FILE__).'/popular_result.php';
file_put_contents($file_path,$html);
echo $html;
} catch(apiServiceException $e) {
echo $e->getMessage();
}
}
else{
echo '<a href="',$client->createAuthUrl(),'">Get token!</a>';
}
?>
<?php
// CSS登録
function register_style(){
wp_register_style('bootstrap','http://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css');
wp_register_style('cc','/css/cc.css');
wp_register_style('sawarabi','https://fonts.googleapis.com/earlyaccess/sawarabimincho.css');
wp_register_style('ccommons','https://cdn.jsdelivr.net/cc-icons/1.2.1/css/cc-icons.min.css'); //'https://cdnjs.cloudflare.com/ajax/libs/cc-icons/1.2.1/css/cc-icons.min.css'
}
function add_stylesheet(){
register_style();
wp_enqueue_style('bootstrap');
wp_enqueue_style('sawarabi');
if(is_singular('post')){wp_enqueue_style('ccommons');}
wp_enqueue_style('cc'); //常に最後に
}
add_action('wp_print_styles','add_stylesheet');
//プラグインCSS排除
function my_deregister_styles(){
wp_deregister_style('pz-linkcard');
wp_deregister_style('math-captcha-frontend');
wp_deregister_style('peg-display.css');
if(!is_page()){wp_deregister_style('contact-form-7');}
if(!is_singular()){wp_deregister_style('toc-screen');}
}
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );