Opening links in slider into new tabs #531
Unanswered
VincentTupper
asked this question in
Q&A
Replies: 1 comment
-
Hello Vincent, All what you have to do is to add
<?php
/*
* Post/Page/CPT Card slider template.
*
* This template can be overriden by copying this file to your-theme/bs-swiper-main/sc-swiper-card.php
*
* @author bootScore
* @package bS Swiper
* @version 5.2.1
Posts:
[bs-swiper-card type="post" category="cars, boats" order="ASC" orderby="date" posts="6"]
Child-pages:
[bs-swiper-card type="page" post_parent="21" order="ASC" orderby="title" posts="6"]
Custom post types:
[bs-swiper-card type="isotope" tax="isotope_category" terms="dogs, cats" order="DESC" orderby="date" posts="5"]
Single items:
[bs-swiper-card type="post" id="1, 15"]
[bs-swiper-card type="page" id="2, 25"]
[bs-swiper-card type="isotope" id="33, 31"]
*/
// Card Slider Shortcode
add_shortcode('bs-swiper-card', 'bootscore_swiper');
function bootscore_swiper($atts) {
ob_start();
extract(shortcode_atts(array(
'type' => 'post',
'order' => 'date',
'orderby' => 'date',
'posts' => -1,
'category' => '',
'post_parent' => '',
'tax' => '',
'terms' => '',
'id' => ''
), $atts));
$options = array(
'post_type' => $type,
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $posts,
'category_name' => $category,
'post_parent' => $post_parent,
);
$tax = trim($tax);
$terms = trim($terms);
if ($tax != '' && $terms != '') {
$terms = explode(',', $terms);
$terms = array_map('trim', $terms);
$terms = array_filter($terms);
$terms = array_unique($terms);
unset($options['category_name']);
$options['tax_query'] = array(array(
'taxonomy' => $tax,
'field' => 'name',
'terms' => $terms,
));
}
if ($id != '') {
$ids = explode(',', $id);
$ids = array_map('intval', $ids);
$ids = array_filter($ids);
$ids = array_unique($ids);
$options['post__in'] = $ids;
}
$query = new WP_Query($options);
if ($query->have_posts()) { ?>
<!-- Swiper -->
<div class="px-5 position-relative">
<div class="cards swiper-container swiper position-static">
<div class="swiper-wrapper">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="swiper-slide card h-auto mb-5">
<?php if ( has_post_thumbnail() ) : ?>
<a target="_blank" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('medium', array('class' => 'card-img-top')); ?>
</a>
<?php endif; ?>
<div class="card-body d-flex flex-column">
<?php bootscore_category_badge(); ?>
<a target="_blank" class="text-body text-decoration-none" href="<?php the_permalink(); ?>">
<?php the_title('<h2 class="blog-post-title h5">', '</h2>'); ?>
</a>
<?php if ('post' === get_post_type()) : ?>
<p class="meta small mb-2 text-muted">
<?php
bootscore_date();
bootscore_author();
bootscore_comments();
bootscore_edit();
?>
</p>
<?php endif; ?>
<p class="card-text">
<a target="_blank" class="text-body text-decoration-none" href="<?php the_permalink(); ?>">
<?= strip_tags(get_the_excerpt()); ?>
</a>
</p>
<p class="card-text mt-auto">
<a target="_blank" class="read-more" href="<?php the_permalink(); ?>">
<?php _e('Read more »', 'bootscore'); ?>
</a>
</p>
<?php bootscore_tags(); ?>
</div>
</div><!-- .card -->
<?php endwhile;
wp_reset_postdata(); ?>
</div> <!-- .swiper-wrapper -->
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
<!-- Add Arrows -->
<div class="swiper-button-next end-0"></div>
<div class="swiper-button-prev start-0"></div>
</div><!-- swiper-container -->
</div>
<!-- Swiper End -->
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}
// Card Slider Shortcode End Links to category, tags, comments and author still open in the same tab. This must be changed in the functions which is simple but not a good idea because they are global and not only for the swiper. If you do not want to make those links clickable, simply add <p class="card-text mt-auto">
<a target="_blank" class="stretched-link read-more" href="<?php the_permalink(); ?>">
<?php _e('Read more »', 'bootscore'); ?>
</a>
</p> Solved? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently im using the basic swiper-card -> [bs-swiper-card type="post" category="partners" order="ASC" orderby="date" posts="10"]. The slider shows up fine with the image and the text underneath saying 'find out more' which opens in the current tab on the browser. How can i change the template code so that this will open in a new tab? I have tried changing the tags in the .php files for each template but have achieved nothing so far.
Beta Was this translation helpful? Give feedback.
All reactions