「Favorites」プラグイン

利用方法

  • Favoritesをインストールして有効化します。
  • 設定>Favoritesをひらきます。
  • Favorites>Displayタブをひらきます。
  • 「Enabled Post Types」から有効化したい投稿タイプを選択します。
  • 「Button Text*」にお気に入りする際の文言を入れます。
  • 「Button Text (Favorited)*」にお気に入り後の文言を入れます。
  • 「変更を保存」を押して保存します。

 

好きな位置に「お気に入りボタン」を入れたい場合

「Insert Before Content」または「Insert After Content」どちらにもチェックを入れずに表示したいテンプレートに以下を挿入すると表示されます。

▼お気に入りボタン(single.phpや特定の固定ページなど)
<?php echo get_favorites_button(get_the_ID()); ?>


▼お気に入りリスト(home.phpや特定の固定ページなど)

<?php
$favorites = get_user_favorites();
if ($favorites) :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$favorites_query = new WP_Query(array(
'post_type' => 'ondemand',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'post__in' => $favorites,
'paged' => $paged,
));
if ($favorites_query->have_posts()) : while ($favorites_query->have_posts()) : $favorites_query->the_post();
?>
<div class="favorit-box">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('session_video') ): ?>
<?php the_field('session_video'); ?>
<?php endif; ?>
<?php the_title(); ?>
</a>
<?php echo get_favorites_button(get_the_ID()); ?>
</div>
<?php endwhile ?>
<?php endif;wp_reset_postdata(); ?>
<?php else : ?>
<p class="text-center">お気に入りがありません。</p>
<?php endif ?>

 

PAGE TOP