Hallo zusammen,
weiter unten seht ihr die index.php meines Themes. Wenn ich es richtig verstehe, werden mit der index.php-Datei die Kategorie-Seiten mit Thumbnails, Überschriften und Textauszügen generiert. Also beispielsweise diese Seite:
https://themes.uxbarn.com/wp/aina/category/lifestyle/
Jetzt möchte ich mit einer Template-Datei eine eigene angepasste Kategorieseite erstellen.
Wie passe ich den folgenden Code an, dass ich Ihn in eine Template-Datei kopieren kann. Anschließend sollten die Auszüge von 3 Posts einer definierten Kategorie ausgegeben werden.
PHP
<?php
/**
* This is the main template file for listing blog posts
*
* @link http://codex.wordpress.org/Template_Hierarchy
*
* @since 1.0.0
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<?php
$list_class = '';
if ( is_home() ) {
$list_class = 'blog-list';
}
if ( is_search() ) {
$list_class = 'search-result-list';
}
if ( is_archive() ) {
$list_class = 'blog-list archive-list';
}
?>
<div class="<?php echo esc_attr( $list_class ); ?>">
<?php get_template_part( 'template-parts/content-top' ); // Additional top section ?>
<?php while ( have_posts() ) : the_post(); // Start the Loop ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
$has_thumbnail_class = 'no-featured-image';
$image_size = 'aina-grid-large';
if ( has_post_thumbnail() ) {
$has_thumbnail_class = 'has-featured-image';
if ( is_search() ) {
echo '<a href="' . esc_url( get_permalink() ) . '">';
echo '<div class="post-image" data-img-src="' . esc_url( get_the_post_thumbnail_url( get_the_ID(), $image_size ) ) . '">';
echo '</div>';
echo '</a>';
} else {
echo '<div class="post-image">';
echo '<a href="' . esc_url( get_permalink() ) . '">';
the_post_thumbnail( $image_size, array( 'title' => get_the_title() ) );
echo '</a>';
echo '</div>';
}
}
?>
<div class="post-content-container clearfix <?php echo esc_attr( $has_thumbnail_class ); ?>">
<div class="post-title-wrapper">
<h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<div class="post-content-wrapper">
<div class="post-content excerpt">
<?php aina_print_post_excerpt(); ?>
</div>
</div>
<?php if ( ! is_search() ) : // Do not display the post meta on the search result page ?>
<?php get_template_part( 'template-parts/content-blog-meta' ); ?>
<?php endif; // ! is_search() ?>
</div>
</article>
<?php endwhile; // End the Loop ?>
</div>
<!-- .blog-list -->
<?php
// Include the post pagination
get_template_part( 'template-parts/pagination' );
?>
<?php
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif; // End if ( have_posts() )
?>
<?php get_footer(); ?>
Alles anzeigen
Hoffe ihr könnt mir weiterhelfen. Danke!
Grüße
Michael