-
Notifications
You must be signed in to change notification settings - Fork 53
/
sidebar.php
executable file
·77 lines (71 loc) · 2.54 KB
/
sidebar.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
<?php
/**
* Sidebar Template.
*/
if ( is_active_sidebar( 'primary_widget_area' ) || is_archive() || is_single() ) :
?>
<div id="sidebar" class="col-md-4 order-md-first col-sm-12 order-sm-last">
<?php
if ( is_active_sidebar( 'primary_widget_area' ) ) :
?>
<div id="widget-area" class="widget-area" role="complementary">
<?php
dynamic_sidebar( 'primary_widget_area' );
if ( current_user_can( 'manage_options' ) ) :
?>
<span class="edit-link"><a href="<?php echo esc_url( admin_url( 'widgets.php' ) ); ?>" class="badge bg-secondary"><?php esc_html_e( 'Edit', 'my-theme' ); ?></a></span><!-- Show Edit Widget link -->
<?php
endif;
?>
</div><!-- /.widget-area -->
<?php
endif;
if ( is_archive() || is_single() ) :
?>
<div class="bg-faded sidebar-nav">
<div id="primary-two" class="widget-area">
<?php
$output = '<ul class="recentposts">';
$recentposts_query = new WP_Query( array( 'posts_per_page' => 5 ) ); // Max. 5 posts in Sidebar!
$month_check = null;
if ( $recentposts_query->have_posts() ) :
$output .= '<li><h3>' . esc_html__( 'Recent Posts', 'my-theme' ) . '</h3></li>';
while ( $recentposts_query->have_posts() ) :
$recentposts_query->the_post();
$output .= '<li>';
// Show monthly archive and link to months.
$month = get_the_date( 'F, Y' );
if ( $month !== $month_check ) :
$output .= '<a href="' . esc_url( get_month_link( get_the_date( 'Y' ), get_the_date( 'm' ) ) ) . '" title="' . esc_attr( get_the_date( 'F, Y' ) ) . '">' . esc_html( $month ) . '</a>';
endif;
$month_check = $month;
$output .= '<h4><a href="' . esc_url( get_the_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'my-theme' ), the_title_attribute( array( 'echo' => false ) ) ) . '" rel="bookmark">' . esc_html( get_the_title() ) . '</a></h4>';
$output .= '</li>';
endwhile;
endif;
wp_reset_postdata();
$output .= '</ul>';
echo $output;
?>
<br />
<ul class="categories">
<li><h3><?php esc_html_e( 'Categories', 'my-theme' ); ?></h3></li>
<?php
wp_list_categories( array( 'title_li' => '' ) );
if ( ! is_author() ) :
?>
<li> </li>
<li><a href="<?php the_permalink( get_option( 'page_for_posts' ) ); ?>" class="btn btn-outline-secondary"><?php esc_html_e( 'more', 'my-theme' ); ?></a></li>
<?php
endif;
?>
</ul>
</div><!-- /#primary-two -->
</div>
<?php
endif;
?>
</div><!-- /#sidebar -->
<?php
endif;
?>