• esgroenewold

    (@esgroenewold)


    Hi guys,
    I’m having problem with get_the_content. It doesn’t work with line breaks or white lines. Here is what I’m trying to do:

    My goal is to show a post’s content in an article when a user clicks on a link containing the post’s title. It works allright unless there is a line break or a white line in the post. Here is the code:

    <?php
                    $posts=get_posts();
                    echo '<ul id="links">';
                    foreach($posts as $post) : setup_postdata($post);
                ?>                     
    
                <li onclick="document.getElementsByTagName('article')[0].innerHTML='<?php echo get_the_content(); ?>'"><a href='#''><?php the_title(); ?></a></li>    
    
                <?php
                    endforeach;
                    echo '</ul>';
                ?>

    So how do I get it to work also with line breaks and/or whitelines?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Jon (Kenshino)

    (@kenshino)

    Lord Jon

    I think you should take a few steps to correct this –

    First don’t do inline Javascript.

    Next, write Javascript using jQuery syntax.

    You can give a class to the <li> tag and have

    jQuery target it via jQuery('.class_name').click() - thats an example

    Google it a little.

    Fix that and see if your line break issue stays.

    Thread Starter esgroenewold

    (@esgroenewold)

    Hi,
    Thank you for your post.
    I have been taught to use javascript in a separate file indeed, but I don’t see how I can make it work then: I need to make links with the post titles as link titles, and the click event on the li’s resulting in the article showing the corresponding post’s content.
    If I use JQuery in a separate file I could target the li’s alright, but how can I make the content of the corresponding post appear in the article?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_content working with line breaks’ is closed to new replies.