WordPress.org

Ready to get started?Download WordPress

Forums

Making whole post from the posts page (index.php) CLICKABLE (5 posts)

  1. leftfooted
    Member
    Posted 5 months ago #

    Hi,

    I need some help. I don't know how to make whole div that contain post clickable. I have 10 posts per page and i need all posts to be clickable and to send users to single posts (single.php). I want to achieve exactly the same effect like Read More link does only i want the whole post to be clickable

    Thanks in advance

  2. bemdesign
    Member
    Posted 5 months ago #

    Not really a WordPress installation question...

    Create a jQuery function in your footer.php (create a child theme before doing this and remember that in WordPress, jQuery is built in but requires jQuery conflict-free coding syntax) that binds a click event to the tag and class/ID that holds a post. You may have to do some JavaScript logic programming to grab the url of the specific post. Anyway, once the post is clicked, redirect the page to the appropriate URL for the post that was clicked.

    Please note that this approach will only work for users who have JavaScript enabled and it may cause accessibility issues.

  3. leftfooted
    Member
    Posted 5 months ago #

    1)i added this between <head></head> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    2) i added this under my step number 1
    <script type="text/javascript">
    $(".myBox").click(function(){
    window.location=$(this).find("a").attr("href");
    return false;
    });
    </script>

    3) i added this in my page content to try if this worksbut it's nt working for me

    <script type="text/javascript">
    $(".myBox").click(function(){
    window.location=$(this).find("a").attr("href");
    return false;
    });
    </script>

    Where is mistake? does anybody know?

    thanks

  4. bemdesign
    Member
    Posted 5 months ago #

    Don't include any external jQuery library! I told you in my first reply that jQuery is already included in WordPress by default and that you can use it right out of the box by using jQuery's no-conflict syntax. See http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers

    Then make sure your functions are called in the footer (or head) of the document - you can't put your jQuery code into your post's text-area form in the admin backend. The code needs to be placed in one of your theme template pages, like footer.php or header.php. And if this isn't your own custom theme, you should look into creating a child theme.

  5. leftfooted
    Member
    Posted 5 months ago #

    Thank you. It is working now

Reply

You must log in to post.

About this Topic