Hi!
The aim of my shortcode is to display all ski images of accessories.
Images are taken from simple Custom Post Type (“akcesoria”): only post title and featured image.
I have prepared two pages to explain the issue.
In both of them I have selected “Insert table of contents” and headings (h3, h4) checkboxes.
First page:
https://skipen.lemonaro.pl/service/services-with-table-of-contents/
Page content:
<h3>Sapien sed neque</h3>
<p>Lorem ipsum dolor sit amet sapien sed neque.</p>
<h4>Sed enim consectetue</h4>
<h3>Fusce quam eu</h3>
<p>Sagittis ultricies. Donec odio a purus. Fusce quam porta nisl.</p>
Second page:
https://skipen.lemonaro.pl/service/services-without-table-of-contents/
Page content:
<h3>Sapien sed neque</h3>
<p>Lorem ipsum dolor sit amet sapien sed neque.</p>
<h4>Sed enim consectetue</h4>
<h3>Fusce quam eu</h3>
<p>Sagittis ultricies. Donec odio a purus. Fusce quam porta nisl.</p>
[display-accessories]
First page displays Table of Contents.
Second not, but displays table of images.
I do not think it is important but just in case there is the snippet of my shortcode:
function display_accessories_function() {
$args = array('post_type' => 'akcesoria',
'post_status' => 'publish',
'posts_per_page'=>-1
);
$loop = new WP_Query( $args );
$unpaired_loop = true;
$number_of_accessories = 0;
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post();
$number_of_accessories = $number_of_accessories + 1;
$akcesorium = get_the_title();
$akcesorium_featured_img_url = get_the_post_thumbnail_url();
if($unpaired_loop){
$col_1 =
'[su_row class=""]
[su_column size="1/2" center="no" class=""]
<h5>' . $akcesorium . '</h5>
<img src="' . $akcesorium_featured_img_url . '" >
[/su_column]';
$unpaired_loop = false;
$last_akcesorium = $akcesorium;
$last_akcesorium_featured_img_url = $akcesorium_featured_img_url;
}
else {
$col_2 =
' [su_column size="1/2" center="no" class=""]
<h5>' . $akcesorium . '</h5>
<img src="' . $akcesorium_featured_img_url . '" >
[/su_column]
[/su_row]';
$unpaired_loop = true;
}
if($unpaired_loop) {
$accessories_table = $accessories_table . $col_1 . $col_2;
}
endwhile;
endif;
if ( $number_of_accessories & 1 ) {
$accessories_table = $accessories_table .
'[su_row class=""]
[su_column size="1/2" center="no" class="kol_1"]
<h5>' . $last_akcesorium . '</h5>
<img src="' . $last_akcesorium_featured_img_url . '" >
[/su_column]
[/su_row]';
}
return do_shortcode($accessories_table);
}
add_shortcode('display-accessories', 'display_accessories_function');