I'm using WordPress and trying to replace the content of a div using JQuery - that bit works. However the content has a URL in it and it isn't working and I cannot see why.
I'm generating a variable in PHP:
$query = new WP_Query( array( 'category_name' => 'news' ) );
if ( $query->have_posts() ) {
// The Loop
while ( $query->have_posts() ) {
$query->the_post();
$news_item = '<h2>' . get_the_title() . '</h2>';
$news_item .= get_the_excerpt();
$news_item .= "<BR>";
$news_item .= "<a href=";
$news_item .= get_permalink();
$news_item .= ">";
$news_item .= "Read More...</a>";
}
wp_reset_postdata();
}
That bit works.
I'm putting that into a jQuery variable:
<script type="text/javascript">
<?php
echo "var newsItem = '{$news_item}';";
?>
jQuery(document).ready(function() {
jQuery('#soap-frontpagenews').fadeOut(500, function() {
jQuery(this).replaceWith(newsItem).fadeIn(500);
});
});
</script>
and that bit works. However the resultant HTML code is not right in the way it fails to produce the link correctly:
<h1>News</h1>
<h2>Taking Better Photos With Your Nikon</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fermentum ac urna et auctor. at…
<br>
<a href="http://212.159.165.84/~soapwp/2013/09/29/taking-better-photos-with-your-nikon"></a>
Read More...
in that Read More... is OUTSIDE the link tags.
Where am I going wrong please?
Best Regards
Dave