这是我的代码: HOME.php:
<?php get_header(); ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'ASC',
'paged' => $paged
);
global $post;
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
?>
<div class="container">
<div class="row">
<?php
while ($the_query->have_posts()) {
$the_query->the_post();
$alt = get_post_meta($post->ID,'_wp_attachment_image_alt', true);
$thumb = get_the_post_thumbnail_url($post->ID, 'medium');
?>
<div class="col-4">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<p><?php echo wp_trim_words(get_the_content(), 4, '...' ); ?></p>
<p><?php the_time('j F Y, H:i'); ?></p>
<a href="<?php echo get_permalink( $post->ID ); ?>">Więcej</a>
</div>
<?php } ?>
<div class="col-12">
<?php the_posts_pagination(array(
'mid_size' => 2,
'prev_text' => 'Previous',
'next_text' => 'Next',
)); ?>
</div>
</div>
</div>
<?php wp_reset_postdata(); } ?>
<form role="search" method="get" action="<?php echo home_url( '/' ); ?>">
<label for="s">Search for:</label>
<input type="text" value="" name="s" id="s" placeholder="<?php the_search_query(); ?>" />
<input type="submit" value="Search" />
</form>
<?php get_footer(); ?>
SINGLE.php
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="col-12">
<?php if (have_posts()) {
while (have_posts()) { the_post();
$thumb_id = get_post_thumbnail_id($post->ID);
$alt = get_post_meta($thumb_id,'_wp_attachment_image_alt', true);
$thumb = get_the_post_thumbnail_url($post->ID, 'medium');
?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<p><?php the_time('j F Y, H:i'); ?></p>
<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a>
<?php $categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '<a href="'.get_category_link($category->term_id).'">'.$category->cat_name.'</a>'.$separator;
}
echo trim($output, $separator);
} ?>
<?php $tags = get_the_tags();
$separator = ", ";
$output = '';
if ($tags) {
foreach ($tags as $tag) {
$output .= '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>'.$separator;
}
echo trim($output, $separator);
} ?>
<?php }
} ?>
</div>
</div>
</div>
<?php get_footer(); ?>
ARCHIVE.php / SEARCH.php
<?php get_header(); ?>
<h2>
<?php if (is_category()) {
single_cat_title();
} elseif ( is_tag() ) {
single_tag_title();
} elseif ( is_author() ) {
the_post();
echo 'Author Archives: ' . get_the_author();
rewind_posts();
} elseif ( is_day() ) {
echo 'Daily Archives: ' . get_the_date();
} elseif ( is_month() ) {
echo 'Monthly Archives: ' . get_the_date('F Y');
} elseif ( is_year() ) {
echo 'Yearly Archives: ' . get_the_date('Y');
} else {
echo 'Archives:';
} ?>
</h2>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'ASC',
'paged' => $paged
);
global $post;
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
?>
<div class="container">
<div class="row">
<?php
while ($the_query->have_posts()) {
$the_query->the_post();
$alt = get_post_meta($post->ID,'_wp_attachment_image_alt', true);
$thumb = get_the_post_thumbnail_url($post->ID, 'medium');
?>
<div class="col-4">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<p><?php echo wp_trim_words(get_the_content(), 4, '...' ); ?></p>
<p><?php the_time('j F Y, H:i'); ?></p>
<a href="<?php echo get_permalink( $post->ID ); ?>">Więcej</a>
</div>
<?php } ?>
<div class="col-12">
<?php the_posts_pagination(array(
'mid_size' => 2,
'prev_text' => 'Previous',
'next_text' => 'Next',
)); ?>
</div>
</div>
</div>
<?php wp_reset_postdata(); } ?>