Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a lazy loading script using AJAX and JSON for my blog. It works perfectly. However I have 4 different blogs on the same site. These are created using custom post types.

I need to get the AJAX to do lazy loading for all of these blogs. I can get it to work for each one by manually changing the name from post to boutiques for example.

So I created a variable called $postname and want to assign this a different value depending on the slug of the page you are on when you click load more posts.

How can i check what page slug is and then assign my variable a name. Here is my code but I need to know how to call the slug of the page im on and assign that to $slug.

if ( $slug == 'boutiques'  ) {

    $postname = 'boutiques';

} elseif ( $slug == 'tourist' ) {

    $postname = 'tourist';
}
else {
    $postname = 'post';
}
share|improve this question

1 Answer 1

assuming you are properly adding the AJAX script to your theme via wp_enqueue_script, you can pass data to the script via wp_localize_script, which you should already be using to pass the path to admin-ajax.php if you are using AJAX correctly within your plugin or theme.

see the Codex page on AJAX for more info. this tutorial linked at the bottom of that page has all the examples you'll need.

a purely javascript solution (which I don't recommend) would be to use the location object to determine context.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.