• Resolved KatrineDS

    (@katrineds)


    Hi,
    Is there a way to show the posts in a slider?
    Any shortcode for that? Would be an awesome feature.
    Best, Katrine

Viewing 1 replies (of 1 total)
  • Plugin Author cyclonecode

    (@cyclonecode)

    I am adding a solution to use a bxslider for the latest three releases for a block with an id equal to ‘frontpage’.

    1. Load needed script and style in your function.php:

    add_action('wp_enqueue_scripts', function() {
        wp_enqueue_script('bxscript', 'https://cdnjs.cloudflare.com/ajax/libs/bxslider/4.2.15/jquery.bxslider.min.js', array ('jquery'), 1.1, true);
        wp_enqueue_style('bxslider', 'https://cdnjs.cloudflare.com/ajax/libs/bxslider/4.2.15/jquery.bxslider.min.css');
    });

    2. Override the template/cision-block.php template to render a block differently then others:

    <?php if (count($cision_feed)) : ?>
    <?php if ($id === 'frontpage'): ?>
        <ul class="bxslider">
            <?php foreach ($cision_feed as $item): ?>
                <li>
                    <h2><?php echo esc_html($item->Title); ?></h2>
                    <time><?php echo date($options['date_format'], $item->PublishDate); ?></time>
                    <p>
                        <?php if (isset($item->Images[0])) : ?>
                        <span class="cision-feed-item-media">
                            <img
                                    src="<?php echo esc_url($item->Images[0]->DownloadUrl); ?>"
                                    alt="<?php echo esc_html($item->Images[0]->Description); ?>"
                                    title="<?php echo esc_html($item->Images[0]->Title); ?>"
                            />
                        </span>
                        <?php endif; ?>
                        <?php echo wp_trim_words(esc_html($item->Intro ? $item->Intro : $item->Body)); ?>
                    </p>
                    <?php if (isset($item->CisionWireUrl, $readmore)) : ?>
                        <a
                                href="<?php echo esc_url($item->CisionWireUrl); ?>"
                                target="<?php echo $item->LinkTarget; ?>"
                        ><?php _e($readmore, CISION_BLOCK_TEXTDOMAIN); ?></a>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    
        <script>
            jQuery(document).ready(function() {
                jQuery('.bxslider').bxSlider({});
            });
        </script>
    <?php else: ?>
    <section<?php echo $wrapper_attributes; ?>>
    <?php echo $prefix; ?>
        <?php foreach ($cision_feed as $item) : ?>
        <article<?php echo $attributes; ?>>
            <h2><?php echo esc_html($item->Title); ?></h2>
            <time><?php echo date($options['date_format'], $item->PublishDate); ?></time>
            <p>
            <?php if (isset($item->Images[0])) : ?>
            <span class="cision-feed-item-media">
            <img
                    src="<?php echo esc_url($item->Images[0]->DownloadUrl); ?>"
                    alt="<?php echo esc_html($item->Images[0]->Description); ?>"
                    title="<?php echo esc_html($item->Images[0]->Title); ?>"
            />
            </span>
            <?php endif; ?>
            <?php echo wp_trim_words(esc_html($item->Intro ? $item->Intro : $item->Body)); ?>
            </p>
            <?php if (isset($item->CisionWireUrl, $readmore)) : ?>
            <a
                    href="<?php echo esc_url($item->CisionWireUrl); ?>"
                    target="<?php echo $item->LinkTarget; ?>"
            ><?php _e($readmore, CISION_BLOCK_TEXTDOMAIN); ?></a>
            <?php endif; ?>
        </article>
        <?php endforeach; ?>
    <?php echo $pager; ?>
    <?php echo $suffix; ?>
    </section>
    <?php endif; ?>
    <?php endif; ?>

    3. Add shortcode in the start page of your theme:

    echo do_shortcode('[cision-block id=frontpage items_per_page=0 count=3]');

    Notice that you need to set items_per_page=0 to avoid using a pager.

Viewing 1 replies (of 1 total)
  • The topic ‘Slider?’ is closed to new replies.