-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.php
104 lines (87 loc) · 2.21 KB
/
blog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
*
* Template Name: Blog
*
* The main template for displaying all posts.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Fredo
*/
get_header(); ?>
<div class="row">
<div class="column">
<h1><?php esc_attr_e( 'All my posts', 'fredo' ); ?></h1>
</div>
</div>
<div class="row home-posts">
<?php
// Create the Query.
$posts_per_page = 8;
$post_type = 'post';
$orderby = 'date';
$order = 'DESC';
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query(
array(
'post_type' => $post_type,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'order' => $order,
'paged' => $paged,
)
);
// Get post type count.
$post_count = $query->post_count;
// Displays info.
if ( $post_count > 0 ) :
// Loop.
while ( $query->have_posts() ) :
$query->the_post();
?>
<div class="column column-50 ">
<span class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
<?php fredo_post_thumbnail( 'medium' ); ?>
<span class="excerpt"><?php the_excerpt(); ?></span>
<span class="button button-black button-small"><a href="<?php the_permalink(); ?>"><?php esc_attr_e( 'Read Now', 'fredo' ); ?></a></span>
</div>
<?php
endwhile;
endif;
?>
<div class="row pagination">
<?php
$total = $query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 ) {
// get the current page.
if ( get_query_var( 'paged' ) !== $current_page ) {
$current_page = 1;
}
// structure of "format" depends on whether we're using pretty permalinks.
if ( empty( get_option( 'permalink_structure' ) ) ) {
$format = '&paged=%#%';
} else {
$format = 'page/%#%/';
}
// Echo pagination.
echo paginate_links(
array(
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => $format,
'total' => $total,
'mid_size' => 4,
'type' => 'list',
)
);
}
?>
</div>
<?php
// Reset query to prevent conflicts.
wp_reset_postdata();
?>
</div>
<?php get_footer(); ?>