WordPress.org

Forums

Getting in jquery function (9 posts)

  1. Shay
    Member
    Posted 2 years ago #

    I currently have code in my header to show an image show in a specific div when clicked. What I would like to do, is have the content show in another div. I managed to get the content to show (outside php), but was wondering if there was a way to get the content from that post to show. The code is below and in script tags. Any advice?

    '$(document).ready(function() {
    $("img").click(function () {
    if ($(this).hasClass("profiles")) {
    $('#student_area').empty()
    var img = $('<img />').attr({ 'src': $(this).attr('src'), 'alt': $(this).attr('alt') }).appendTo($('#student_area'));
    $("div.student_desc").empty()
    var div = $('<div><?php get_the_content (); ?>This is the content</div>').attr({ 'alt': $(this).attr('alt') }).appendTo($('div.student_desc'));
    }
    });
    });'

  2. billcolumbia
    Member
    Posted 2 years ago #

    Try replacing '$' with 'jQuery'. I think wordpress reserves $ for something else.

  3. Shay
    Member
    Posted 2 years ago #

    Which '$'? The script works, just the <?php get_the_content (); ?> doesnt.

  4. billcolumbia
    Member
    Posted 2 years ago #

    I don't think get_the_content returns the info. I think the_content does. If you use get_the_content you need to store it in a variable or something.

  5. Shay
    Member
    Posted 2 years ago #

    It still didn't work with the_content. I wonder if the way I have the code, its trying to print the content from the image itself and not the post.

  6. billcolumbia
    Member
    Posted 2 years ago #

    Is your code inside the loop?

  7. Shay
    Member
    Posted 2 years ago #

    Yes it is.

  8. billcolumbia
    Member
    Posted 2 years ago #

    Interesting. Sorry I couldn't help.

  9. Shay
    Member
    Posted 2 years ago #

    It's ok. It's all a learning experience :) Thank you for your help!

Topic Closed

This topic has been closed to new replies.

About this Topic