0
jQuery(document).ready(function($) {        
            $('a.ttLinks').click(function() {

                 var url= $(this).attr("href"); 
                   $("#inCenter>[id^=featuredv]").load(url);    
                 return false;
 });
});  

I tried making a script that loads the contents of a link when it is clicked rather than reloading the page. I'm not certain why but it seems that when a link is clicked it loads the actual page that I'm currently on into my featuredv div instead of just the contents of the post. I think when a permalink is clicked on, it loads the post into index.php and then returns the page to me.

<div id="ttContent">
<?php
query_posts('meta_key=featuredt&posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post();
?>
<div id="featuredt-<?php echo $wp_query->current_post;?>">
<a class="ttLinks" rel="<?php the_permalink(); ?>" href="<?php echo the_permalink();?>">
<?php echo get_post_meta($post->ID, 'featuredt', TRUE);?></a></div>                                     
<?php endwhile;
endif;
?>
</div>

the code above is the php I'm using to generate my links, I was originally using href but after reading another post, Load Wordpress post content into DIV using AJAX , I thought maybe I should try using the rel tag instead, there wasn't a difference since either way the url is the same but I was tired and trying anything I could.

<div id="inCenter">
<?php
query_posts('meta_key=featuredt&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<div id="featuredv-<?php  echo $wp_query->current_post;?>">
<?php echo $post->post_content;?></div>
<?php endwhile;
endif;
?>
</div>

And this code is what generates the content that I want to replace when a link is clicked. What firebug seems to be showing is that the first time a link is clicked it sends a GET request for the permalink which in the page it's displayed in, the second time any of the links are clicked it sends 4 GET requests for the permalink, the next time 12 and so on. I'm not using wordpress as a blog and I don't have a place for the posts to load to so maybe the posts are loading using the index.php by default when the GET request is made? Thanks again for the help.

Community
  • 1
  • 1

2 Answers2

1

You should post your HTML to clarify, but unless you're storing the target page's location in the rel attribute (as opposed to the more intuitive href) element, then you'll need to change your line to read var url=$(this).attr("href");

I'm just assuming the line directly below this line isn't actually in your code (in which case would cause it to not be parseable). Please make the changes to your question as needed. You only need to post the relevant HTML code (i.e. the a.ttlinks tags and the #inCenter div (with contents)).

Paul Zaczkowski
  • 2,848
  • 1
  • 25
  • 26
  • Yes I was storing the location in the rel attribute, sorry for the poorly worded question and sparse details, I was very tired and incredibly frustrated, I've updated my question though if you wouldn't mind taking another look. – redappleorigin Nov 03 '11 at 20:56
0

Okay so the answer was incredibly simple, all I had to do was make a single.php with code that said

<?php echo $post->post_content; ?>

and the code works. I don't have a page that loads my posts since I'm not using wordpress as a blog, I didn't think I needed one, but I didn't have any code telling the .js what to load so it was just loading the default index.php. Now my code works perfectly! Or, at least it works well at the moment, I still have some testing to do. Sorry if I frustrated anyone with my question, I just didn't know how to ask my question correctly.