サポート » 使い方全般 » 記事上部へのカテゴリ説明の挿入方法

  • 解決済 mitsuruchange30sfrom2021

    (@mitsuruchange30sfrom2021)


    お忙しいところ恐れ入ります。
    表題の件で、ご質問させてください。

    https://mitsurublog.com/category/way-of-living/powerful-quotes/
    上記、カテゴリのトップページにおいて、カテゴリ説明(「今までの人生で、・・・・ 読んでいただくと道が開けるかもしれません。」の部分)が表示されております。

    このカテゴリに属する子ページにおいても、同位置(パンくずリストと記事の間)に、カテゴリ説明を表示させたいのですが、方法をご教示いただけないでしょうか。

    カテゴリ説明を表示させたいのは、カテゴリ名「人生を変えてくれる名言集1の子ページ投稿記事のみであり、それ以外のカテゴリの投稿記事については、現状のまま、カテゴリ説明を表示させたくありません。

    よろしくお願いいたします。

    ヘルプの必要なページ: [リンクを見るにはログイン]

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • ルクセリタスは個別ページのその位置にウィジェット領域が存在していないので、カテゴリアーカイブと同じ配置にしたいのであればテーマに手を加える作業が必要になります。
    具体的にはsingle.phpに手を加えることになります。

    子テーマにsingle.phpをコピーして、パンくずとclass=”post”の間に以下のようにコードを入れてください。

    if( $luxe['breadcrumb_view'] === 'inner' ) get_template_part( 'breadcrumb' );
    ?>
    <!-- カテゴリ説明追加 -->
    <?php if ( in_category('カテゴリのid') ) : ?>
    <div class="category-description toc grid clearfix"><?php echo category_description('カテゴリのid'); ?></div>
    <?php else: ?>
    <?php endif; ?>
    <!-- ここまで -->
    <div itemprop="mainEntityOfPage" id="mainEntity" <?php post_class('post'); ?>>

    特定カテゴリ内の投稿(in_category)の場合は特定カテゴリの説明(category_description)を表示するという記述です。

    ルクセリタスのテーマアップデートでsingle.phpが更新された時は同じ手順の作業をし直す必要があります。記述や仕様の変更が原因で古いままだと正常に動かないということがあるからです。

    • この返信は2年、 11ヶ月前にmoyo55が編集しました。
    トピック投稿者 mitsuruchange30sfrom2021

    (@mitsuruchange30sfrom2021)

    回答ありがとうございます。初歩的なところで申し訳ありませんが、追加でご質問させてください。

    >子テーマにsingle.phpをコピーして
    とございますが、`

    ルクセリタスの親テーマのsingle.phpを、子テーマにコピーするという理解であっておりますでしょうか??

    認識が合っている場合、以下がテーマのsingle.phpとなるのですが、
    どの部分に、いただいたコードを入れればよいかご教示いただけないでしょうか。

    パンくずとclass=”post”の間が具体的に、以下のどこかが判別できませんでした。
    スキル不足で申し訳ありません。。。

    ■ルクセリタスの親テーマのsingle.php
    ————————————————

    <?php
    /**
     * Luxeritas WordPress Theme - free/libre wordpress platform
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2 of the License, or
     * (at your option) any later version.
     *
     * @copyright Copyright (C) 2015 Thought is free.
     * @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
     * @author LunaNuko
     * @link https://thk.kanzae.net/
     * @translators rakeem( http://rakeem.jp/ )
     */
    
    global $luxe, $_is, $awesome;
    get_header();
    
    $fa_pencil	= 'fa-pencil-alt';
    $fa_file	= 'fa-file-alt';
    
    if( $awesome['ver'][0] === '4' ) {
    	$fa_pencil	= 'fa-pencil';
    	$fa_file	= 'fa-file-text';
    }
    ?>
    <article>
    <div id="core" class="grid">
    <?php
    if( $luxe['breadcrumb_view'] === 'inner' ) get_template_part( 'breadcrumb' );
    ?>
    <div itemprop="mainEntityOfPage" id="mainEntity" <?php post_class('post'); ?>>
    <?php
    if( function_exists('dynamic_sidebar') === true ) {
    	if( isset( $luxe['amp'] ) ) {
    		if( is_active_sidebar('post-title-upper-amp') === true ) {
    			$amp_widget = thk_amp_dynamic_sidebar( 'post-title-upper-amp' );
    			if( !empty( $amp_widget ) ) echo $amp_widget;
    		}
    	}
    	else {
    		if( is_active_sidebar('post-title-upper') === true ) {
    			dynamic_sidebar( 'post-title-upper' );
    		}
    	}
    }
    
    if( have_posts() === true ) {
    	while( have_posts() === true ):
    	the_post();
    
    	// <h1> タイトル
    	?><header id="article-header"><?php
    	$span = false;
    	if( isset( $luxe['thumb_auto_post'] ) && isset( $luxe['thumb_auto_insert_position'] ) ) {
    		if(  $luxe['thumb_auto_insert_position'] === 'top' ) {
    			$post_thumbnail = has_post_thumbnail();
    			if( $post_thumbnail === true ) {	// タイトル上サムネイル
    				echo '<figure id="post-thumbnail">', thk_get_the_post_thumbnail( $post->ID, 'full', array( 'itemprop' => 'image', 'class' => 'post_thumbnail' ) ), '</figure>';
    			}
    		}
    		if( $luxe['thumb_auto_insert_position'] === 'background' ) {
    			$span = true;	// <span> タグ付き (タイトルに background 入れる場合)
    		}
    	}
    	echo apply_filters( 'thk_h_tag', 1, '', 'headline name', '', 'entry-title', $span );
    	?></header><?php
    
    	if( isset( $luxe['thumb_auto_post'] ) && isset( $luxe['thumb_auto_insert_position'] ) ) {
    		if( $luxe['thumb_auto_insert_position'] === 'below' ) {
    			$post_thumbnail = has_post_thumbnail();
    			if( $post_thumbnail === true ) {	// タイトル下サムネイル
    				echo '<figure id="post-thumbnail">', thk_get_the_post_thumbnail( $post->ID, 'full', array( 'itemprop' => 'image', 'class' => 'post_thumbnail' ) ), '</figure>';
    			}
    		}
    	}
    	?><div class="clearfix"><?php
    
    	get_template_part('meta');
    	if( isset( $luxe['sns_tops_enable'] ) ) {
    		// SNS 記事上
    		$luxe['sns_layout'] = 'tops';
    		if( isset( $luxe['amp'] ) ) {
    			ob_start();
    			get_template_part( 'sns' );
    			$sns_top = ob_get_clean();
    			echo thk_amp_not_allowed_tag_replace( $sns_top );
    		}
    		else {
    			get_template_part( 'sns' );
    		}
    	}
    
    	if( isset( $luxe['thumb_auto_post'] ) ) {
    		if( isset( $luxe['thumb_auto_insert_position'] ) && $luxe['thumb_auto_insert_position'] === 'above' ) {
    			$post_thumbnail = has_post_thumbnail();
    			if( $post_thumbnail === true ) {	// タイトル下サムネイル
    				echo '<figure id="post-thumbnail">', thk_get_the_post_thumbnail( $post->ID, 'full', array( 'itemprop' => 'image', 'class' => 'post_thumbnail' ) ), '</figure>';
    			}
    		}
    	}
    
    	if( function_exists('dynamic_sidebar') === true ) {
    		if( isset( $luxe['amp'] ) ) {
    			if( is_active_sidebar('post-title-under-amp') === true ) {
    				$amp_widget = thk_amp_dynamic_sidebar( 'post-title-under-amp' );
    				if( !empty( $amp_widget ) ) echo $amp_widget;
    			}
    		}
    		else {
    			if( is_active_sidebar('post-title-under') === true ) {
    				dynamic_sidebar( 'post-title-under' );
    			}
    		}
    	}
    
    	//the_content();
    	echo apply_filters( 'thk_content', '' ); // 本文
    
    	if( function_exists('dynamic_sidebar') === true ) {
    		if( isset( $luxe['amp'] ) ) {
    			if( is_active_sidebar('post-under-1-amp') === true ) {
    				$amp_widget = thk_amp_dynamic_sidebar( 'post-under-1-amp' );
    				if( !empty( $amp_widget ) ) echo $amp_widget;
    			}
    		}
    		else {
    			if( is_active_sidebar('post-under-1') === true ) {
    				dynamic_sidebar( 'post-under-1' );
    			}
    		}
    	}
    ?>
    </div>
    <?php
    	echo apply_filters( 'thk_link_pages', '' );
    ?>
    <div class="meta-box">
    <?php
    	$luxe['meta_under'] = true;
    	get_template_part('meta');
    
    	$author = get_the_author();
    
    	if( isset( $luxe['author_visible'] ) && !empty( $author ) ) {
    		if( $luxe['author_page_type'] === 'auth' ) {
    ?>
    <p class="vcard author"><i class="<?php echo $awesome['fas'], $fa_pencil; ?>"></i><?php echo __( 'Posted by', 'luxeritas' ); ?> <span class="fn" itemprop="editor author creator copyrightHolder"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo $author; ?></a></span><?php
    		}
    		else {
    ?>
    <p class="vcard author"><i class="<?php echo $awesome['fas'], $fa_pencil; ?>"></i><?php echo __( 'Posted by', 'luxeritas' ); ?> <span class="fn" itemprop="editor author creator copyrightHolder"><a href="<?php echo isset( $luxe['thk_author_url'] ) ? $luxe['thk_author_url'] : THK_HOME_URL; ?>"><?php echo $author; ?></a></span><?php
    		}
    ?></p>
    <?php
    	}
    	if( isset( $luxe['hide_luxe_adminbar'] ) && $_is['edit_posts'] === true && $_is['customize_preview'] === false ) {
    		$post_link = get_edit_post_link();
    		if( isset( $post_link ) ) {
    			echo '<p class="vcard author">[ ';
    			if( isset( $luxe['amp_enable'] ) ) {
    				$amp_permalink = thk_get_amp_permalink( get_queried_object_id() );
    				if( isset( $luxe['amp'] ) ) {
    					echo	' <i class="', $awesome['fas'], 'fa-chevron-circle-left"></i><a href="', wp_get_canonical_url(), '">', __( 'Origin', 'luxeritas' ), '</a>'
    					,	' ⚡ <a href="https://validator.ampproject.org/#url=', $amp_permalink, '" target="_blank" rel="noopener noreferrer">', __( 'Validate', 'luxeritas' ), '</a>'
    					,	' ⚡ <a href="https://cdn.ampproject.org/c/', ( stripos( $amp_permalink, 'https:' ) !== false ) ? 's/' : '', str_replace( array( 'http://', 'https://'), '', $amp_permalink ), '" target="_blank" rel="noopener noreferrer">', __( 'Cache', 'luxeritas' ), '</a>';
    				}
    				else {
    					echo	' <i class="', $awesome['fas'], $fa_file, '"></i>';
    					edit_post_link( __( 'Edit This', 'luxeritas' ) );
    					echo	' ⚡ <a href="', $amp_permalink, '#development=1">AMP</a>';
    				}
    			}
    			else {
    				edit_post_link( __( 'Edit This', 'luxeritas' ) );
    			}
    			echo ' ]</p>';
    		}
    	}
    ?>
    </div><!--/.meta-box-->
    <?php
    	if( isset( $luxe['sns_bottoms_enable'] ) || ( function_exists('dynamic_sidebar') === true && is_active_sidebar('post-under-1') === true ) ) {
    		echo '<hr class="pbhr" />';
    	}
    ?>
    </div><!--/.post-->
    <aside>
    <?php
    	if( function_exists('dynamic_sidebar') === true ) {
    		if( isset( $luxe['amp'] ) ) {
    			if( is_active_sidebar('post-under-2-amp') === true ) {
    				$amp_widget = thk_amp_dynamic_sidebar( 'post-under-2-amp' );
    				if( !empty( $amp_widget ) ) echo $amp_widget;
    			}
    		}
    		else {
    			if( is_active_sidebar('post-under-2') === true ) {
    				dynamic_sidebar( 'post-under-2' );
    			}
    		}
    	}
    
    	if( isset( $luxe['sns_bottoms_enable'] ) ) {
    		if( isset( $luxe['sns_bottoms_msg'] ) ) {
    ?>
    <div class="sns-msg" ><h2><?php echo $luxe['sns_bottoms_msg']; ?></h2></div>
    <?php
    		}
    		// SNS 記事下
    		$luxe['sns_layout'] = null;
    		if( isset( $luxe['amp'] ) ) {
    			ob_start();
    			get_template_part( 'sns' );
    			$sns_bottom = ob_get_clean();
    			echo thk_amp_not_allowed_tag_replace( $sns_bottom );
    		}
    		else {
    			get_template_part( 'sns' );
    		}
    	}
    	endwhile;
    }
    else {
    	?><p><?php echo __( 'No posts yet', 'luxeritas' ); ?></p><?php
    }
    ?>
    </aside>
    </div><!--/#core-->
    <aside>
    <?php
    if( isset( $luxe['next_prev_nav_visible'] ) ) {
    ?>
    <div id="pnavi" class="grid">
    <?php
    	$wp_upload_dir = wp_upload_dir();
    
    	//$next_post = get_next_post();
    	$next_post = get_adjacent_post( false, '', false );
    	if( $next_post ) {
    		$thumb = 'thumb100';
    		$image_id = get_post_thumbnail_id( $next_post->ID );
    		$image_url = wp_get_attachment_image_src( $image_id, $thumb );
    
    		if( isset( $image_url[0] ) ) {
    			$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
    
    			if( file_exists( $image_path ) === false ) {
    				$thumb = 'thumbnail';
    			}
    		}
    		else {
    			$thumb = 'thumbnail';
    		}
    		$next_thumb = thk_get_the_post_thumbnail( $next_post->ID, $thumb );
    		if( empty( $next_thumb ) ) $next_thumb = '<div class="no-img-next"><i class="' . $awesome['fas'] . $fa_file . '"></i></div>';
    ?>
    <div class="next"><?php next_post_link( '%link', $next_thumb . '<div class="ntitle">' . $next_post->post_title . '</div><div class="next-arrow"><i class="' . $awesome['fas'] . 'fa-arrow-right fa-pull-right"></i>' . __( 'Next', 'luxeritas' ) . '</div>' ); ?></div>
    <?php
    	}
    	else {
    ?>
    <div class="next"><a href="<?php echo THK_HOME_URL; ?>"><i class="<?php echo $awesome['fas']; ?>fa-home navi-home"></i><div class="next-arrow"><i class="<?php echo $awesome['fas']; ?>fa-arrow-right fa-pull-right"></i><?php echo __( 'Home ', 'luxeritas' ); ?></div></a></div>
    <?php
    	}
    	//$prev_post = get_previous_post();
    	$prev_post = get_adjacent_post( false, '', true );
    	if( $prev_post ) {
    		$thumb = 'thumb100';
    		$image_id = get_post_thumbnail_id( $prev_post->ID );
    		$image_url = wp_get_attachment_image_src( $image_id, $thumb );
    
    		if( isset( $image_url[0] ) ) {
    			$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
    
    			if( file_exists( $image_path ) === false ) {
    				$thumb = 'thumbnail';
    			}
    		}
    		else {
    			$thumb = 'thumbnail';
    		}
    		$prev_thumb = thk_get_the_post_thumbnail( $prev_post->ID, $thumb );
    		if( empty( $prev_thumb ) ) $prev_thumb = '<div class="no-img-prev"><i class="' . $awesome['fas'] . $fa_file . ' fa-rotate-180"></i></div>';
    ?>
    <div class="prev"><?php previous_post_link( '%link', $prev_thumb . '<div class="ptitle">' . $prev_post->post_title . '</div><div class="prev-arrow"><i class="' . $awesome['fas'] . 'fa-arrow-left fa-pull-left"></i>' . __( 'Prev', 'luxeritas' ) . '</div>' ); ?></div>
    <?php
    	}
    	else {
    ?>
    <div class="prev"><a href="<?php echo THK_HOME_URL; ?>"><i class="<?php echo $awesome['fas']; ?>fa-home navi-home"></i><div class="prev-arrow"><i class="<?php echo $awesome['fas']; ?>fa-arrow-left fa-pull-left"></i><?php echo __( 'Home ', 'luxeritas' ); ?></div></a></div>
    <?php
    	}
    ?>
    </div><!--/.pnavi-->
    <?php
    }
    
    // 関連記事
    $_is_active_related_upper = false;
    $_is_active_related_under = false;
    
    if( isset( $luxe['amp'] ) ) {
    	$_is_active_related_upper = is_active_sidebar('related-upper-amp');
    	$_is_active_related_under = is_active_sidebar('related-under-amp');
    }
    else {
    	$_is_active_related_upper = is_active_sidebar('related-upper');
    	$_is_active_related_under = is_active_sidebar('related-under');
    }
    
    if( isset( $luxe['related_visible'] ) || $_is_active_related_upper === true || $_is_active_related_under === true ) {
    ?>
    <div id="related-box" class="grid">
    <?php
    	// 関連記事上ウィジェット
    	if( function_exists('dynamic_sidebar') === true && $_is_active_related_upper === true ) {
    		if( isset( $luxe['amp'] ) ) {
    			$amp_widget = thk_amp_dynamic_sidebar( 'related-upper-amp' );
    			if( !empty( $amp_widget ) ) echo $amp_widget;
    		}
    		else {
    			dynamic_sidebar( 'related-upper' );
    		}
    	}
    
    	if( isset( $luxe['related_visible'] ) ) {
    ?>
    <h2 class="related"><i class="<?php echo $awesome['fas']; ?>fa-th-list"></i><?php echo __( 'Related Posts', 'luxeritas' ); ?></h2>
    <?php
    		if( isset( $luxe['amp'] ) ) {
    			ob_start();
    			get_template_part( 'related' );
    			$sns_bottom = ob_get_clean();
    			echo thk_amp_not_allowed_tag_replace( $sns_bottom );
    		}
    		else {
    			//get_template_part( 'related' );
    			echo apply_filters('thk_related', '');
    		}
    	}
    
    	// 関連記事下ウィジェット
    	if( function_exists('dynamic_sidebar') === true && $_is_active_related_under === true ) {
    		if( isset( $luxe['amp'] ) ) {
    			$amp_widget = thk_amp_dynamic_sidebar( 'related-under-amp' );
    			if( !empty( $amp_widget ) ) echo $amp_widget;
    		}
    		else {
    			dynamic_sidebar( 'related-under' );
    		}
    	}
    ?>
    </div><!--/#related-box-->
    <?php
    }
    
    // コメント欄
    if( isset( $luxe['comment_visible'] ) ) {
    	if( $_is['comments_open'] === true || get_comments_number() > 0 ){
    		echo apply_filters('thk_comments', '');
    	}
    }
    
    // トラックバックURL
    if( isset( $luxe['trackback_visible'] ) && pings_open() === true ) {
    ?>
    <div id="trackback" class="grid">
    <h3 class="tb"><i class="<?php echo $awesome['fas']; ?>fa-reply-all"></i><?php echo __( 'TrackBack URL', 'luxeritas' ); ?></h3>
    <input type="text" name="trackback_url" aria-label="Trackback url" size="60" value="<?php trackback_url() ?>" readonly="readonly" class="trackback-url" tabindex="0" accesskey="t" />
    </div>
    <?php
    }
    ?>
    </aside>
    </article>
    </main>
    <?php thk_call_sidebar(); ?>
    </div><!--/#primary-->
    <?php echo apply_filters( 'thk_footer', '' ); ?>
    トピック投稿者 mitsuruchange30sfrom2021

    (@mitsuruchange30sfrom2021)

    回答ありがとうございます。初歩的なところで申し訳ありませんが、追加でご質問させてください。

    >子テーマにsingle.phpをコピーして
    とございますが、`

    ルクセリタスの親テーマのsingle.phpを、子テーマにコピーするという理解であっておりますでしょうか??

    どの部分に、いただいたコードを入れればよいかご教示いただけないでしょうか。
    パンくずとclass=”post”の間が具体的にどこかが判別できませんでした。

    スキル不足で申し訳ありません。。。

    そうです。「親テーマのsingle.phpを、子テーマにコピー」します。
    で、記述場所をミスしていました。
    正しくは、single.php内の上の方にある

    <article>
    <div id="core" class="grid">

    <article>
    <!-- カテゴリ説明追加 -->
    <?php
    $cate_id = "11"; // カテゴリのid
    if ( in_category( $cate_id ) ) : ?>
    <div class="category-description grid clearfix"><?php echo category_description( $cate_id ); ?></div>
    <?php else: ?>
    <?php endif; ?>
    <!-- ここまで -->
    <div id="core" class="grid">

    となるように書き換えてください。
    表示したいカテゴリのidを記述するのを忘れないでください。

    ————————-
    テーマに手を加えるのはリスクがある上にメンテナンスの手間が増えるので、
    カテゴリ一覧表示の時ととちょっと位置・デザインが変わっても良いのであれば、ルクセリタスのショートコード機能を使って個別ページのタイトル上にカテゴリ説明文を表示するという方法もあります。

    その場合は…
    ダッシュボード → Luxeritas → ショートコード登録 → 新規追加

    ラベル: 個別ページにカテゴリ説明文表示
    ショートコード: my_category_description cate_id=””
    下部の「PHP Code」と「有効化」にチェックを入れる
    contents入力欄に

    if ( is_single() && in_category( $args["cate_id"] ) ) {
    	$cate_desc = category_description( $args["cate_id"] ); 
    	$contents = '<div class="category-description clearfix">'. $cate_desc .'</div>';
    }

    と入力し保存する。

    記事タイトル上ウィジェットにテキストウィジェットやカスタムhtmlウィジェット、アドセンスウィジェットのいずれかを設置してショートコード [my_category_description cate_id=”カテゴリid”] を設置する。
    (広告/アドセンスウィジェットを使うと表示範囲をより細かく設定できます。)

    最後に、cssでデザインを指定します。例えば

    .single .category-description {
    	border:1px solid #ddd;
    	padding:25px;
    }

    など。

    • この返信は2年、 11ヶ月前にmoyo55が編集しました。
    • この返信は2年、 11ヶ月前にmoyo55が編集しました。
    • この返信は2年、 11ヶ月前にmoyo55が編集しました。

    テーマに手を加えるのはリスクがある上にメンテナンスの手間が増えるので、
    カテゴリ一覧表示の時ととちょっと位置・デザインが変わっても良いのであれば、ルクセリタスのショートコード機能を使って個別ページのタイトル上にカテゴリ説明文を表示するという方法もあります。
    (不慣れなうちは見た目に違いが出ても、ショートコードを使うこっちの手順の方が良いと思います)

    承認待ち処理を食らってるので手順は私のブログの方に載せました

    トピック投稿者 mitsuruchange30sfrom2021

    (@mitsuruchange30sfrom2021)

    ご丁寧にありがとうございます。

    single.phpのやり方と、
    ショートコード機能のやり方の
    両方試しまして、両方とも動作確認できました。

    運用手間がかかることを考慮して、ショートコードの方で、
    当面は動かそうと思います。

    お忙しいところ本当にありがとうございました。

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • トピック「記事上部へのカテゴリ説明の挿入方法」には新たに返信することはできません。