Skip to content

Instantly share code, notes, and snippets.

@x-genki

x-genki/*.php Secret

Last active August 27, 2022 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-genki/0fabedb7963ec0168b0f93a1f442c559 to your computer and use it in GitHub Desktop.
Save x-genki/0fabedb7963ec0168b0f93a1f442c559 to your computer and use it in GitHub Desktop.
Snowmonkeyの固定ページでサブループを回して、最後にページネーションを表示
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'posts_per_page' => 1,
'paged' => $paged,
'post_type' => 'report',
'tax_query' => array(
array(
'taxonomy' => 'report_cat',
'field' => 'slug',
'terms' => array('experiment', 'introduction'),
),
),
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
?>
<div class="p-archive">
<div class="c-container">
<ul class="c-entries c-entries--rich-media">
<?php
while ($the_query->have_posts()) : $the_query->the_post();
$post_id = get_the_ID();
$title = get_the_title($post_id);
$permalink = get_permalink($post_id);
$post_thumbnail_url = get_the_post_thumbnail_url($post_id, 'large');
?>
<li class="c-entries__item">
<section class="c-entry-summary c-entry-summary--farmer c-entry-summary--type-farmer">
<a href="<?php echo esc_url($permalink); ?>" style="background-image: url(<?php echo esc_url($post_thumbnail_url); ?>);">
<header class="c-entry-summary__header">
<h2 class="c-entry-summary__title"><?php echo esc_html($title); ?></h2>
</header>
</a>
</section>
</li>
<?php
endwhile;
?>
</ul>
</div><!-- /.c-container -->
</div><!-- /.p-archive -->
<?php
}
wp_reset_postdata();
// ページネーション
if (!empty($the_query->max_num_pages) && 2 <= $the_query->max_num_pages) {
\Framework\Helper::get_template_part('template-parts/archive/pagination');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment