post.php
5.07 KB
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
105
106
<?php
/**
* Post template in Recent Posts Block
*/
$archive_year = get_the_time('Y');
$archive_month = get_the_time('m');
$archive_day = get_the_time('d');
$imageSize = ( ( isset($attributes['imageSize']) && $attributes['imageSize'] ) ? $attributes['imageSize'] : 'post-thumbnail');
$showTitle = isset( $attributes['showTitle'] ) && $attributes['showTitle'];
$showFeaturedImage = isset( $attributes['showFeaturedImage'] ) && $attributes['showFeaturedImage'] && has_post_thumbnail();
$showCategories = isset( $attributes['showCategories'] ) && $attributes['showCategories'] && has_category();
$showCommentsCount = isset( $attributes['showCommentsCount'] ) && $attributes['showCommentsCount'] && comments_open();
$showContent = isset( $attributes['showContent'] ) ? $attributes['showContent'] : false;
$showDate = isset( $attributes['showDate'] ) && $attributes['showDate'];
$contentLength = isset( $attributes['contentLength'] ) ? $attributes['contentLength'] : false;
/**
*
* @TODO: Temporary fix wpautop
*
*/
remove_filter('the_content', 'wpautop');
?>
<article id="post-<?php the_ID(); ?>" class="<?php echo esc_attr($extra_attr['block_name'].'__post');?>">
<div class="<?php echo esc_attr($extra_attr['block_name'].'__post-wrapper');?>">
<?php if ( $showFeaturedImage ) { ?>
<div class="<?php echo esc_attr($extra_attr['block_name']); ?>__post-thumbnail">
<a href="<?php echo esc_url(get_permalink()); ?>"><?php
the_post_thumbnail( $imageSize, array('alt' => the_title_attribute( 'echo=0' )));
?></a>
</div>
<?php } ?>
<?php
if($showTitle || $showDate || $showContent || $showCategories || $showCommentsCount):
?>
<div class="<?php echo esc_attr($extra_attr['block_name'])?>__content-wrapper">
<?php
if($showTitle || $showDate):
?>
<header class="<?php echo esc_attr($extra_attr['block_name'])?>__entry-header">
<?php if ( $showTitle ) { ?>
<?php the_title( '<'.esc_attr($attributes['titleTag']).' class="'.esc_attr($extra_attr['block_name']).'__post-title"><a href="'.esc_url(get_permalink()).'">', '</a></'.esc_attr($attributes['titleTag']).'>' ); ?>
<?php } ?>
<?php
if($showDate):
?>
<div class="<?php echo esc_attr($extra_attr['block_name'])?>__entry-meta">
<?php if ( $showDate ) { ?>
<span class="<?php echo esc_attr($extra_attr['block_name']); ?>__post-date">
<time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>"><a href="<?php
echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day) ); ?>"><?php
echo esc_html( get_the_date( '' ) );
?></a></time>
</span>
<?php } ?>
</div>
<?php
endif;
?>
</header>
<?php
endif;
?>
<?php if ( $showContent ) {
?><div class="<?php echo esc_attr($extra_attr['block_name']); ?>__post-content"><?php
echo esc_html( wp_trim_words( get_the_excerpt(), $contentLength ) );
?></div>
<?php } ?>
<?php
if ( $showCategories || $showCommentsCount ) :
?>
<footer class="<?php echo esc_attr($extra_attr['block_name'])?>__entry-footer">
<?php if ( $showCategories ) { ?>
<p class="<?php echo esc_attr($extra_attr['block_name']); ?>__post-categories">
<?php echo get_the_category_list(', '); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</p>
<?php } ?>
<?php if ( $showCommentsCount ) { ?>
<p class="<?php echo esc_attr($extra_attr['block_name']); ?>__post-comments">
<a href="<?php echo esc_url( get_comments_link() ); ?>"><?php
if ( get_comments_number() ) {
//translators: %d is a comments count
echo esc_html( sprintf( _n( '%d Comment', '%d Comments', get_comments_number(), 'getwid' ), get_comments_number() ) );
} else {
echo esc_html__( 'No comments', 'getwid' );
}
?></a>
</p>
<?php } ?>
</footer>
<?php
endif;
?>
</div>
<?php
endif;
?>
</div>
</article>