月火水木金土日
   1234
567891011
12131415161718
19202122232425
262728293031 
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
1234567
891011121314
15161718192021
22232425262728
293031    
       
 123456
78910111213
14151617181920
21222324252627
28      
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
    123
45678910
11121314151617
18192021222324
25262728293031
       
  12345
6789101112
13141516171819
20212223242526
27282930   
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
   1234
567891011
12131415161718
19202122232425
262728293031 
       
 123456
78910111213
14151617181920
21222324252627
282930    
       
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
1234567
891011121314
15161718192021
22232425262728
       
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
   1234
567891011
12131415161718
19202122232425
262728293031 
       
 123456
78910111213
14151617181920
21222324252627
282930    
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
1234567
891011121314
15161718192021
22232425262728
2930     
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
    123
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
   1234
567891011
12131415161718
19202122232425
262728293031 
       
1234567
891011121314
15161718192021
293031    
       
     12
3456789
10111213141516
17181920212223
24252627282930
       
  12345
6789101112
20212223242526
2728293031  
       
1234567
891011121314
15161718192021
22232425262728
2930     
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
    123
11121314151617
25262728   
       
14151617181920
21222324252627
28293031   
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
22232425262728
293031    
       
     12
3456789
10111213141516
24252627282930
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      
   1234
567891011
19202122232425
262728293031 
       
   1234
567891011
12131415161718
19202122232425
262728    
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
  12345
6789101112
13141516171819
27282930   
       
      1
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
     12
3456789
10111213141516
24252627282930
31      
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
     12
3456789
10111213141516
       
  12345
6789101112
20212223242526
2728293031  
       
  12345
6789101112
2728     
       
      1
23242526272829
3031     
   1234
567891011
12131415161718
       
 123456
78910111213
14151617181920
21222324252627
282930    
       
   1234
567891011
12131415161718
19202122232425
2627282930  
       
1234567
891011121314
15161718192021
22232425262728
293031    
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
  12345
6789101112
13141516171819
20212223242526
27282930   
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
    123
45678910
11121314151617
18192021222324
252627282930 
       
 123456
78910111213
28293031   
       
1234567
891011121314
15161718192021
22232425262728
29      
       
    123
45678910
11121314151617
18192021222324
       
 123456
78910111213
21222324252627
28293031   
       
      1
16171819202122
30      
   1234
19202122232425
262728293031 
       
 123456
78910111213
14151617181920
282930    
       
     12
3456789
10111213141516
17181920212223
24252627282930
31      
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
    123
45678910
11121314151617
18192021222324
25262728293031
       
  12345
6789101112
13141516171819
20212223242526
27282930   
       
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
      1
2345678
9101112131415
16171819202122
232425262728 
       
   1234
12131415161718
19202122232425
262728293031 
       
891011121314
22232425262728
293031    
       
     12
3456789
10111213141516
17181920212223
24252627282930
       
  12345
6789101112
13141516171819
20212223242526
2728293031  
       
1234567
891011121314
15161718192021
22232425262728
2930     
       
    123
45678910
25262728293031
       
 123456
78910111213
14151617181920
21222324252627
28293031   
       
      1
2345678
9101112131415
16171819202122
23242526272829
30      

表示中の記事と同じカテゴリの人気記事を表示する方法:WordPress

 

現在表示している記事と同じカテゴリーの人気記事のリストを表示するには?  

WPP Plus Widget というプラグインを使ってみたら、その記事の所属カテゴリーだけに限定することができず、その記事のカテゴリーの親のカテゴリーの記事まで表示されてしまう不思議に遭遇した。

他にも時間の表示フォーマットを変更できなかったり、不具合があったので使用停止。  

PHP Code Widget に独自PHPコードを放り込むほうが良い。

 

Simple GA Ranking プラグインの機能を使用するので、インストールしておく。  

 

 

<h4 class="widgettitle"><span class="side-title-inner">
<?php
// SHOW YOAST PRIMARY category, OR FIRST category
$category = get_the_category();
$useLink = true;
// If post has a category assigned.
if ($category){
	$category_display = '';
	$category_link = '';
	if ( class_exists('WPSEO_Primary_Term') )
	{
		// Show the post's 'Primary' category, if this Yoast feature is available, & one is set
		$wpseo_primary_term = new WPSEO_Primary_Term( 'category', get_the_id() );
		$wpseo_primary_term = $wpseo_primary_term->get_primary_term();
		$term = get_term( $wpseo_primary_term );
		if (is_wp_error($term)) { 
			// Default to first category (not Yoast) if an error is returned
			$category_display = $category[0]->name;
			$category_link = get_category_link( $category[0]->term_id );
			$category_slug = $category[0]->slug;
			$now_id = $category[0]->term_id; 
		} else { 
			// Yoast Primary category
			$category_display = $term->name;
			$category_link = get_category_link( $term->term_id );
			$category_slug = $term->slug;
			$now_id = $term->term_id; 
		}
	} 
	else {
		// Default, display the first category in WP's list of assigned egories
  $category_display = $category[0]->name;
  $category_slug = $category[0]->slug;
  $category_link = get_category_link( $category[0]->term_id );
  $category_id = $term->term_id;
  $now_id = $category[0]->term_id; 

	}
	// Display category
	if ( !empty($category_display) ){
	    if ( $useLink == true && !empty($category_link) ){
		echo '<a href="'.$category_link.'">'.htmlspecialchars($category_display).'</a>';
	    } else {
		echo ''.htmlspecialchars($category_display).'';
	    }
	}
}
?>
 カテゴリ人気記事</span></h4>
 <?php
$sga_args = array(
    'display_count' => 8, //5件表示する
    'period'        => 90, 
    ''  => $category_slug
  );

    $sga_args = wp_parse_args( $sga_arg_, $sga_args );

  /**
   * ランキングデータ取得
   */
  $ranking_data = sga_ranking_get_date( $sga_args );
  /**
   * ランキング作成
   */
if ( !empty( $ranking_data ) ):
  echo '<ul class="wpp-list wpp-list-with-thumbnails">';
    foreach ( $ranking_data as $post_id ):
?>

<li>
<a href="<?php the_permalink($post_id); ?>" title="<?php the_title_attribute($post_id); ?>">
 <?php
	$post_title = get_the_title($post_id);
echo get_the_post_thumbnail($post_id, 'wpp348x208', array( 'class' => 'wpp-thumbnail wpp_featured_stock ', 'alt' => $post_title,'title' => $post_title) );
	?>
</a>
<span class="wpp-views"><?php echo get_post_meta($post_id, views, true); ?></span>

<a href="<?php echo get_permalink($post_id); ?>" title="<?php the_title_attribute($post_id); ?>" class="wpp-post-title" >
<?php echo get_the_title($post_id); ?>
</a>
<span class="wpp-excerpt"><?php echo get_the_excerpt_by_id($post_id, 100) ?></span>
<?php $archive_year  = get_the_time( 'Y',$post_id ); ?>
<?php $archive_month = get_the_time( 'm',$post_id ); ?>
<a href="<?php echo get_month_link( $archive_year, $archive_month ); ?>" class="wpp-date"><span class="wpp-date"> <?php echo get_the_time('Y.n.j',$post_id); ?> 
</span></a>
<span class="wpp-category-all"><?php the_category(' ','',$post_id) ?> </span>
</li>
<?php
    endforeach;
  echo '</ul>';
endif;
wp_reset_postdata();
?>

 

 メインカテゴリを取得するために、Yoast SEO プラグイン の機能を使用するので、インストールしておく。  

表示しないページを細かく設定するには ダイナミックウィジェットDynamic Widgets プラグインが便利。

過去記事アーカイブのページでは非表示するなどの設定ができる。

 

 

 

  • 2685年6月4日

    VPSの移転方法

    VPSメモリ:2GB月額1,530円~CPU 3CoreNVMe SSD 150GB から、 メモリ:2GB 月額690円~ CPU2Core NVMe SSD50GBに移転成功した。朝から5時間ぐらいかかって落ち着いた感じ。 移転の動機は、年間支出削減。8,544円/年 で、さらに、30%をキャッシュバックのキャンペーンだったから。同一の会社だがサービスグレードの違いのみの新規追加VPS契約した。まずs1 からs2(移転先サーバー 192.168.1.2)にSSHログインできるようにする。# s1でSSH鍵生成(まだなければ)ssh-keygen -t rsa -b 4096# Enterキーを3回押してデフォルト設定 # s2に公開鍵をコピ...
  • またまたこのサイトのSSL証明書が期限切れになった。 Kusanagi の自動更新ができていない。 それで手動であれこれしてみても、こんなエラーが出る。# kusanagi update cert Challenge failed for domain makotoiwasaki.com Challenge failed for domain www.makotoiwasaki.com Attempting to renew cert (makotoiwasaki.com) from /etc/letsencrypt/renewal/makotoiwasaki.com.conf produced an unexpected error: Some challenges hav...
  • Google の Indexing API を使うと、新しい投稿記事を瞬時にGoogleの検索エンジンに登録できる。 WordPress のプラグインとしてインデックスAPIが利用できる。使い方は英語だが、この通り: ⏱️ Get Google To Index Your Website Instantly Using the Indexing API ⚡Take a look at how you can use Google's new indexing API & to get your website's pages and content crawled instantly instead of waiting for Google to...
  • Yoast SEO を停止して、Rank Math SEO プラグインを使ってみたらGoogle の検索結果に表示される記事抜粋スニペットの文字数が短過ぎに見えてびっくりした。#1 Yoast Alternative You Deserve - Rank Math SEO vs. Yoast SEORank Math SEO plugin for WordPress is hands down the best Yoast alternative WordPress plugin. And the best thing is, Rank Math is completely FREE!Rank Math
  • WP_CRON を停止して、Linux の crontab に移行する設定をこれまでに何度も試みたがうまくいかなかった。 毎日バックアップされるはずの、UpdraftPlus プラグインのクロンが動いていない。やっと成功した設定方法を記録しておく。wp-config.php に次の行を追加する。define('DISABLE_WP_CRON', true);/var/spool/cron  に、  httpd という名前のファイルを作成し、次の1行を追加する。 所有者を httpd.www など、httpd nginx サーバーの稼働ユーザー名と同じにする。nginx.conf に書いてある。root@s4:/v...
  • Kusanagi WordPress プラットフォームでは Fcache とBcache がある。 Fcache とはNginx ヱブサーバーのキャッシュ機能であり、Kusanagi の独自機能ではない。Nginx のアクセスログを眺めていると、  BYPASS MISS EXPIRED のみで、HITが殆どない。 トップ頁、アーカイブリストの頁ではHIT、 個別投稿頁では、BYPASS MISS EXPIRED ばかりでHITがない。Kusanagi fcache on とすると、fcache は有効になったかのように思えるが、本当にキャッシュが効いているのかどうかはログで確認しないとわからない。まず、Wordpressの編集画面にログインし...
  • HTTPD アクセスログの日本語化 Nginx,  Apache ヱブサーバーのアクセスログを見ると、日本語URLはエンコードされていて読めない。 そこで、デコードして表示させる。 ログのファイル名が ssl_access.log だとすると、tail -f ssl_access.log| perl -ne 'use URI::Escape; print uri_unescape($_);' tail -f access.log | php -R 'echo urldecode($argn)."\n";'で、日本語URlが読める状態で出力される。 Apacheのログをデコードする方法 - Life with ITプログラマ x ...
  • ヱブサイトの再構築中には、スタイルシート、style.css を頻繁に調整更新する。 CSSを追加、編集する度に再読み込みを繰り返して、変更の反映を確認していた。 これで編集者は反映を確認できるのだが、一般閲覧者はわざわざ再読み込みしたり、キャッシュを削除したりするはずはないので、変更が反映されていない崩れたデザインを見ているかもしれない。わざわざリロードしたりキャッシュを削除したりしなくても変更が確実に反映されるような設定方法を発見した。wp_enqueue_scripts で CSS、JS の読み込みを管理している場合には、次のようにfunctions.php に記述する。// 子テーマのstyle.cssを最後に読み込む add_acti...

タグクラウド

風邪(2)著者(3)豆(6)車旅(21)香港(16)酒(26)麻(10)鶏(22)野鳥(1)蛙(2)車(71)蝶(12)長寿(3)踊(3)麺(32)蜂(16)遺跡(3)鰻(1)象(25)靴(1)

WordPress カテゴリ人気記事 Views most

タグ関連記事

閲覧履歴