Discordコミュニティを作りました! 参加する

フォーラム

トピックを立てる前にチェック
  1. フォーラムガイドライン」に必ず目を通してください。
  2. バージョンアップデート後に表示がおかしくなった場合は、
    「SWELL設定」>「リセット」からキャッシュクリアを先にお試しください。
  3. フォーラム内検索で過去に同じようなトピックがないか検索してみてください。
記事スライダーにも「抜粋文」を表示した...
 
通知
すべてクリア

記事スライダーにも「抜粋文」を表示したい

2 投稿
2 ユーザー
1 Likes
960 表示
yamowo
(@yamowo)
投稿: 32
メンバー
Topic starter
 

いつもお世話になっております。

「記事一覧リスト」や「投稿リスト」ブロックと同様に、

「記事スライダー」でも「抜粋文」を表示させることは可能でしょうか。

(フックで挿入できればそれでもいいのですが、判りませんでした…)

記事スライダー

ご検討のほど、よろしくお願いいたします。

SWELLでニッチなカスタマイズして遊んでます #ヤモヲのひとりあそび

 
投稿済 : 17/03/2022 6:35 pm
tsubasa-swell
(@tsubasa-swell)
投稿: 3
メンバー
 

投稿者さまと同じようなことを実現したく、子テーマのカスタマイズを行ったためご参考になれば幸いです。

loop_by_slider.php (parts/post_list/loop_by_slider.php)を選んで、以下のコードを追記したらスライダーに抜粋の表示ができました。

---------

<?php
if ( ! defined( 'ABSPATH' ) ) exit;
 
/**
 * 記事スライダーの投稿リスト出力テンプレート
 */
$query_args  = isset($variable['query_args']) ? $variable['query_args'] : [];
$thumb_sizes = isset($variable['thumb_sizes']) ? $variable['thumb_sizes'] : '';
 
// 表示設定
$show_date     = SWELL_Theme::get_setting( 'ps_show_date' );
$show_modified = SWELL_Theme::get_setting( 'ps_show_modified' );
$show_author   = SWELL_Theme::get_setting( 'ps_show_author' );
$cat_pos       = SWELL_Theme::get_setting( 'pickup_cat_pos' );
 
// クエリの取得
if ( !empty($query_args) ) {
    $the_query = new WP_Query( apply_filters( 'swell_pickup_post_args', $query_args ) );
} else {
    $the_query = null;
}
 
// 表示枚数
$ps_num_sp = SWELL_Theme::get_setting( 'ps_num_sp' );
 
?>
<ul class="p-postSlider__postList p-postList swiper-wrapper">
<?php
if ( $the_query && $the_query->have_posts() ) :
$ct = 0;
while ( $the_query->have_posts() ) :
$ct++;
$the_query->the_post();
 
$post_data = get_post();
$the_id    = $post_data->ID;
$the_title = get_the_title();
 
if ( mb_strwidth( $the_title, 'UTF-8' ) > 120 ) :
$the_title = mb_strimwidth( $the_title, 0, 120, '...', 'UTF-8' );
endif;
?>
<li class="p-postList__item swiper-slide">
<a href="<?php the_permalink( $the_id ); ?>" class="p-postList__link">
<?php
SWELL_Theme::get_parts(
'parts/post_list/item/thumb',
[
'post_id'   => $the_id,
'cat_pos'   => $cat_pos,
'size'      => 'large',
'sizes'     => $thumb_sizes,
'decoding'  => 'async',
'lazy_type' => $ct > $ps_num_sp ? SWELL_Theme::$lazy_type : 'none',
]
);
?>
<div class="p-postList__body">
<h2 class="p-postList__title">
<?=wp_kses( $the_title, SWELL_Theme::$allowed_text_html )?>
</h2>
<div class="p-postList__meta">
<?php
// 日付
SWELL_Theme::get_parts( 'parts/post_list/item/date', [
'show_date'     => $show_date,
'show_modified' => $show_modified,
] );
if ( 'on_title' === $cat_pos ) :
SWELL_Theme::pluggable_parts( 'post_list_category', [
'post_id' => $the_id,
] );
endif;
 
if ( $show_author ) :
SWELL_Theme::pluggable_parts( 'post_list_author', [
'author_id' => $post_data->post_author,
] );
endif;
?>
</div>
<div class="p-postList__excerpt">
<?=wp_kses_post( get_the_excerpt() )?>
</div>
</div>
</a>
</li>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
 
 
投稿済 : 07/06/2024 9:34 am
共有: