Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:04:38+00:00 2026-05-31T06:04:38+00:00

I am creating a wordpress blog that has small boxes for each post thumbnail.

  • 0

I am creating a wordpress blog that has small boxes for each post thumbnail. When you click one, it expands and loads the post with ajax. For this functionality, I would want to load JUST what’s in the post, and not a bunch of extra html around it. However, in order to provide permanent links or the ability for people to share posts and link directly to them from Facebook or whatever, I will still need a single post template that DOES include all the extra html and page formatting.

In short, I’d like to be able to link to a single post using its permalink, and additionally I’d like to be able to bring in the stripped down version of it using a jquery .load()

Here’s what I have in my functions file:

function my_template_redirect() {
global $wp_query;
if ( 'ajax' == $wp_query->query_vars['name'] ) {
    $wp_query->is_404 = false;
    status_header( 200 );
    $args = array(
            'p' => $post->ID,
            'post_type' => $post->post_type
            );
    query_posts( $args );
    the_post();
    load_template(  TEMPLATEPATH . '/ajax-single.php' );
    die();
    }
}

add_action( 'template_redirect',  'my_template_redirect' );

So now, when I load a post using its normal permalink, like ( http://www.page.com/permalink ), it loads the normal single.php version, and when I load a post like this: ( http://www.page.com/permalink/ajax ) it shows a stripped down version using ajax-single.php as the page template. The problem is, it’s loading ALL the posts at once in the ajax version, rather than just the one in question. How do I make sure it’s only loading the one that I want?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:04:39+00:00Added an answer on May 31, 2026 at 6:04 am

    I discovered the best solution in an article called Developing Sites With AJAX: Design Challenges and Common Issues

    The reason this is the best solution is because when you make an ajax call to load a page fragment, it loads the entire page first and then returns the fragment. You improve this functionality by using php, which when placed in the page in the following manner, will only return the data requested by the server. The first option responds to the page being loaded by any jquery .load() function, and the second responds when the page is loaded by a browser in the typical manner.

    <?php if($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest'){?>
    This is content requested by AJAX.
    <?php }?>
    
    <?php if($_SERVER['HTTP_X_REQUESTED_WITH']==''){?>
    This is the normal content requested in a browser
    <?php }?>
    

    Here is an example: http://icant.co.uk/articles/things-to-know-about-ajax/header-switching.html

    Make sure to check out the full article to see more details on how it can be correctly applied in WordPress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a wordpress blog.I had a Tutorial but i cant uderstand that
I've tried creating a new post on my Wordpress blog and I've pasted an
I'm creating a plugin for wordpress and I need to check if a post
I have 2 custom fields in my WordPress system when creating new posts. One
I am creating a small utility which will help to rebuild install.php of WordPress.
I am creating a wordpress blog for a magazine. They have a legacy blog
I am creating a Wordpress blog (no live link yet because it's still at
I'm creating a wordpress plugin and I was wondering if wordpress has any function
Suppose I'm creating a Wordpress website with user login and a small e-commerce. When
WordPress 3.2.1 I'm creating separate page templates, however, there are some page templates that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.