Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, by a stroke of luck and some coffee with cigarettes, I managed to resolve the issue:</p> <p>Here's what I did:</p> <p><strong>1. Test if post ID is captured in the rel attribute and loaded properly in the post_id variable</strong></p> <p>I inserted an alert call back on the AJAX / JQUERY snippet to see if the post ID was even loading into the post_id variable right. This is how it looked like:</p> <pre><code>$(document).ready(function(){ $.ajaxSetup({cache:false}); $(".trick").click(function(){ var post_id = $(this).attr("rel"); alert(post_id); $("#single-home-container").html("loading..."); $("#single-home-container").load("http://&lt;?php echo $_SERVER[HTTP_HOST]; ?&gt;/single-home/",{id:post_id}); return false; }); }); </code></pre> <p>So when I clicked on the link, the call back gave the accurate post ID associated with the post. This kinda isolated the problem right down to the URL defined in the .load() function. It seemed that the post ID was just not sufficient to load the post into defined DIV.</p> <p><strong>2. Change link's rel attribute from post ID to post permalink</strong></p> <p>I decided that since the post ID was clearly not working I would instead use the post's permalink tag in the link's rel attribute. This is how it link's rel looked like previously:</p> <pre><code>&lt;a class="trick" rel="&lt;?php the_ID(); ?&gt;" href="&lt;?php the_permalink();?&gt;"&gt;&lt;/a&gt; </code></pre> <p>And this is how it looks like now:</p> <pre><code>&lt;a class="trick" rel="&lt;?php the_permalink ?&gt;" href="&lt;?php the_permalink();?&gt;"&gt;&lt;/a&gt; </code></pre> <p><strong>3. Edit .load() function URL / value</strong></p> <p>Following on from there, I had to make a change to the AJAX / JQUERY snippet so that it will not use the post ID anymore:</p> <pre><code>$(document).ready(function(){ $.ajaxSetup({cache:false}); $(".trick").click(function(){ var post_link = $(this).attr("rel"); $("#single-home-container").html("loading..."); $("#single-home-container").load(post_link); return false; }); }); </code></pre> <p>As you can see from the above, I've taken the link's rel attribute value (which is now the post's permalink) and thrown it into the post_link variable. This enables me to simply take that variable and place it into the .load() function, replacing <code>http://&lt;?php echo $_SERVER[HTTP_HOST]; ?&gt;/single-home/",{id:post_id}</code> which obviously didn't work.</p> <p>VOILA! Problem solved.</p> <p>Though I have yet to test this, I believe that using the permalink in this instance actually cuts out the need to change the permalink structure in Wordpress as instructed by Emanuele Feronato in his <a href="http://www.emanueleferonato.com/2010/04/01/loading-wordpress-posts-with-ajax-and-jquery/" rel="nofollow noreferrer">post</a>.</p> <p>So if anyone has the intent to dynamically load Wordpress posts into a defined DIV, you can probably try this out!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload