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

91 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2022-04-24 23:11:44 +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'];
$thiscategory = $args['category_name'];
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
?>
<section class="category-posts <?php echo $thiscategory;?> ">
<header>
<h2>
<?php
if ( is_category() ):
single_cat_title();
else:
echo $thiscategory;
endif;
?>
</h2>
</header>
<main class="">
<?php $the_query = new WP_Query( array( 'category_name' => $thiscategory, 'posts_per_page' => $howmanyposts , 'paged' => $paged ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<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">
<?php
if ( is_category( 'news' ) ):
the_date('d.m.Y');
else:
the_date('Y');
endif;
?>
</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>
</article>
<?php endwhile;//end of the loop ?>
</main>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
</main>
<?php endif; ?>
<aside>
<?php //get_template_part( 'template-parts/navigation', 'prevnext' ); ?>
<nav>
2022-04-29 10:43:05 +02:00
<div class="post-next"><?php next_posts_link( __( '&larr; Older', 'foundationpress' ) ); ?></div>
<div class="post-previous"><?php previous_posts_link( __( 'Newer &rarr;', 'foundationpress' ) ); ?></div>
2022-04-24 23:11:44 +02:00
<?php
// button load more simple
// echo '<a class="button hollow" href="' . esc_url( get_category_link( get_cat_ID($thiscategory) ) ) . '">';
// echo 'load more ' ;
// echo $thiscategory;
// echo '</a>';
?>
</nav>
</aside>
</section>