arc-hive-wordpress-theme/template-parts/section-categoryposts.php

75 lines
2.3 KiB
PHP
Raw Normal View History

2021-04-29 11:47:25 +02:00
<?php
/**
* The section containing preview of news category posts
*
* @package arcHIVE-theme
* @since arcHIVE-theme 1.0.0
*/
?>
<?php
//https://developer.wordpress.org/reference/functions/get_template_part/#comment-4130
// var_dump( $args ); //will display everythin imported from
// get_template_part( 'template-parts/section', 'category', array('category_name' => 'news', 'post_per_page' => '3' ) );
$howmanyposts = $args['post_per_page'];
2022-04-11 03:31:19 +02:00
$thiscategory = $args['category_name'];
?>
<section class="category-posts <?php echo $thiscategory;?> ">
2021-04-29 11:47:25 +02:00
<header>
2022-04-11 03:31:19 +02:00
<h2>
<?php
if ( is_category() ):
single_cat_title();
else:
echo $thiscategory;
endif;
?>
</h2>
2021-04-29 11:47:25 +02:00
</header>
<main class="">
<?php $the_query = new WP_Query( array( 'category_name' => $thiscategory, 'posts_per_page' => $howmanyposts ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
2021-04-29 11:47:25 +02:00
<article class="">
<?php if ( has_post_thumbnail() ) :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo get_the_post_thumbnail_url();?>);">
</figure>
</a>
<?php else :?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<figure style="background-image: url(<?php echo catch_post_first_image();?>);">
</figure>
</a>
<?php endif;?>
<h5 class="date">
2021-06-28 16:24:49 +02:00
<?php //the_date('d.m.Y');?>
</h5>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
<section class="excerpt post-excerpt">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_excerpt() ?>
</a>
</section>
2021-04-29 11:47:25 +02:00
</article>
<?php endwhile;//end of the loop ?>
<?php //pagination here ?>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
2021-04-29 11:47:25 +02:00
</main>
<aside>
<nav>
2021-04-30 01:38:35 +02:00
<!--a href="" class="button hollow">see more news</a-->
2021-04-29 11:47:25 +02:00
</nav>
</aside>
</section>