Skip to content

Commit c5ca354

Browse files
committed
format tabs to bootstrap 5
1 parent a4b03b7 commit c5ca354

File tree

2 files changed

+106
-3
lines changed

2 files changed

+106
-3
lines changed

init.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
die( '-1' );
1818
}
1919

20-
require_once __DIR__ . '/src/class-query-shortcode.php';
20+
// Load class for shortcode.
21+
require_once __DIR__ . '/src/class-queryshortcode.php';
2122

22-
$query_shortcode = new Query_Shortcode();
23+
// Instantiate the main class.
24+
$query_shortcode = new QueryShortcode();
2325

2426
// Allow shortcodes in widget areas.
2527
add_filter( 'widget_text', 'do_shortcode' );

lenses/tabs.php

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
<?php/** * Tabs lens file * * This file produces tabs widget out of queried posts. * Please note, for this widget to work, Twiiter Bootstrap's stylesheet and script file must already be in the page. * * @since 0.2 */if( $posts->have_posts() ) { static $tabs_instance; $tabs_instance++; $i = 0; ?><ul class="nav nav-tabs" id="tabs-<?php echo $tabs_instance ?>"> <?php while( $posts->have_posts() ) : $posts->the_post(); ?> <li<?php echo ( $i++ == 0 ? ' class="active"' : '' ); ?>><a data-toggle="tab" href="#tabs-<?php echo $tabs_instance . $i ?>"><?php the_title(); ?></a></li> <?php endwhile; $i = 0; ?> </ul> <div class="tab-content"> <?php while( $posts->have_posts() ) : $posts->the_post(); ?> <div class="tab-pane<?php echo ( $i++ == 0 ? ' active' : '' ); ?>" id="tabs-<?php echo $tabs_instance . $i ?>"> <?php the_content(); ?> </div> <?php endwhile; ?> </div><?php}wp_reset_postdata();
1+
<?php
2+
/**
3+
* Tabs lens file
4+
*
5+
* This file produces tabs widget out of queried posts.
6+
* Please note, for this widget to work, Twiiter Bootstrap's stylesheet and script file must already be in the page.
7+
*
8+
* @package custom-query-shortcode
9+
* @since 0.2
10+
* @version 0.5.0
11+
*/
12+
13+
// Prevent direct access.
14+
if ( ! defined( 'ABSPATH' ) ) {
15+
exit;
16+
}
17+
18+
if ( $this->query->have_posts() ) {
19+
static $tabs_instance;
20+
++$tabs_instance;
21+
$i = 0;
22+
23+
$tabs_id = sprintf( 'tabs-%s', cqs_random_string() );
24+
$tabs_target = sprintf( '#%s', esc_attr( $tabs_id ) );
25+
26+
?><ul class="nav nav-tabs" id="<?php echo esc_attr( $tabs_id ); ?>" role="tablist">
27+
<?php
28+
while ( $this->query->have_posts() ) :
29+
$this->query->the_post();
30+
31+
$tab_name_base = sprintf( '%1$s-%2$s', get_the_ID(), substr( get_post_field( 'post_name' ), 0, 12 ) );
32+
33+
$tab_id = sprintf( '%s-tab', $tab_name_base );
34+
$pane_target = sprintf( '#%s-tab-pane', $tab_name_base );
35+
$pane_id = sprintf( '%s-tab-pane', $tab_name_base );
36+
37+
$tab_atts_array = array(
38+
'class' => 'nav-link',
39+
'id' => $tab_id,
40+
'data-bs-toggle' => 'tab',
41+
'data-bs-target' => $pane_target,
42+
'type' => 'button',
43+
'role' => 'tab',
44+
'aria-controls' => $pane_id,
45+
'aria-selected' => ( 0 === $i ) ? 'true' : 'false',
46+
);
47+
48+
if ( 0 === $i ) {
49+
$tab_atts_array['class'] .= ' active';
50+
}
51+
52+
$tab_attributes = cqs_print_html_attributes( $tab_atts_array );
53+
54+
?>
55+
<li class="nav-item" role="presentation">
56+
<button <?php echo wp_kses_data( $tab_attributes ); ?>><?php the_title(); ?></button>
57+
</li>
58+
<?php
59+
++$i;
60+
endwhile;
61+
?>
62+
</ul>
63+
<div class="tab-content" id="<?php echo esc_attr( $tabs_id ); ?>-content">
64+
65+
<?php
66+
$p = 0;
67+
while ( $this->query->have_posts() ) :
68+
$this->query->the_post();
69+
70+
$tab_name_base = sprintf( '%1$s-%2$s', get_the_ID(), substr( get_post_field( 'post_name' ), 0, 12 ) );
71+
72+
$tab_id = sprintf( '%s-tab', $tab_name_base );
73+
$pane_id = sprintf( '%s-tab-pane', $tab_name_base );
74+
75+
$pane_atts_array = array(
76+
'class' => 'tab-pane fade border border-top-0 rounded-1 py-2 px-3',
77+
'id' => $pane_id,
78+
'role' => 'tabpanel',
79+
'aria-labelledby' => $tab_id,
80+
'tabindex' => 0,
81+
);
82+
83+
84+
$pane_classes = array();
85+
if ( 0 === $p ) {
86+
$pane_atts_array['class'] .= ' show active';
87+
}
88+
89+
$pane_attributes = cqs_print_html_attributes( $pane_atts_array );
90+
91+
?>
92+
<div <?php echo wp_kses_data( $pane_attributes ); ?>>
93+
<?php the_excerpt(); ?>
94+
</div>
95+
<?php
96+
++$p;
97+
endwhile;
98+
?>
99+
</div>
100+
<?php
101+
}
102+
wp_reset_postdata();

0 commit comments

Comments
 (0)