Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1487337

    Dear people on the support forum,

    I am creating a website on this domain:

    Here, I have 2 sections with post sliders in a 3-column layout. Right now, the featured image, title and read more link are linked to the full article.
    Is there a way to make the entire excerpt column clickable?

    Your help will be highly appreciated!

    #1487372

    Hey pelgrimrat,

    Thank you for the inquiry.

    You can add this code in the functions.php file to make the excerpt clickable with the same link as the title and featured image.

    function ava_custom_script_mod() {
        ?>
        <script>
        // make post grid excerpt clickable
        jQuery(document).ready(function($) {
            $('article.slide-entry').each(function() {
                const $article = $(this);
                const link = $article.find('a.slide-image').attr('href');
    
                if (link) {
                    const $excerpt = $article.find('.slide-entry-excerpt');
    
                    $excerpt.css('cursor', 'pointer').on('click', function(e) {
                        if (!$(e.target).closest('a').length) {
                            window.location.href = link;
                        }
                    });
                }
            });
        });
        </script>
        <?php
    }
    add_action( 'wp_footer', 'ava_custom_script_mod', 9999 );
    

    Let us know the result.

    Best regards,
    Ismael

    #1487415

    Hello Ismael,

    Thanks for your reply and code!
    I have added this code and it works on the excerpt p text, so that’s nice.

    But my wish is the make the entire area clickable. By this I mean the entire column with the post preview, including the background.

    So is CSS that would be the “.avia-content-slider article.slide-entry” area.

    Is this also possible?

    #1487444

    Hi,

    Thank you for the update.

    We adjusted the script a bit. Please remove the previous modification and replace it with the following code:

    function ava_custom_script_mod() {
        ?>
        <script>
        // make post grid excerpt clickable
        jQuery(document).ready(function($) {
            $('article.slide-entry').each(function() {
                const $article = $(this);
                const link = $article.find('a.slide-image').attr('href');
    
                if (link) {
                    $article.css('cursor', 'pointer').on('click', function(e) {
                        if (!$(e.target).closest('a, button').length) {
                            window.location.href = link;
                        }
                    });
                }
            });
        });
        </script>
        <?php
    }
    add_action('wp_footer', 'ava_custom_script_mod', 9999);

    Best regards,
    Ismael

    #1487889

    Hi Ismael,

    Thank you for the updated script. It works fine!

    Please mark this topic as resolved.

    #1487946

    Hi,

    Great, I’m glad that Ismael could help you out. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘make entire column clickable in post slider’ is closed to new replies.