I want to load the new entries without reloading the page.
I found a great solution for:
The ajax script:

    $(document).ready(function() {
    var refreshId = setInterval(function()
    }, 10000);


And the php:

<?php require_once("wp-blog-header.php"); ?>
<div id="content" <?php cyberchimps_filter_content_class(); ?>>

        <?php do_action( 'cyberchimps_before_content'); ?>

        <?php if ( have_posts() ) : ?>

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', get_post_format() ); ?>

            <?php endwhile; ?>

        <?php elseif ( current_user_can( 'edit_posts' ) ) : ?>

            <?php get_template_part( 'no-results', 'index' ); ?>

        <?php endif; ?>

        <?php do_action( 'cyberchimps_after_content'); ?>


However, this is a special feature that works perfectly here: http://neocsatblog.mblx.hu/test/ However, the main page refuses to load new entries, I do not understand the reason for this, as we use everything the same.

  • Start by checking the home page for script errors. There are lots of them. – murdaugh Oct 5 '13 at 15:41
  • Which may be the most serious, which hangs in the function? – Szántai Ádám Oct 5 '13 at 15:44
  • XMLHttpRequest cannot load http://neocsatblog.mblx.hu/new.php. Origin http://www.neocsatblog.mblx.hu is not allowed by Access-Control-Allow-Origin. You have a cross domain issue which needs to be solved. Using jQuery's load() to pull in cross-domain requests is problematic. See this: stackoverflow.com/questions/3889001/… – murdaugh Oct 5 '13 at 15:50
  • That's just the crap in the chat, you think if you turn it off and work normally? :D – Szántai Ádám Oct 5 '13 at 16:00

Try changing your script to this since you're not actually running a cross-browser request:

(function($) {
  $(document).ready(function() {
    var refreshId = setInterval(function()
      $("#content .span9 article").unwrap();
    }, 10000);

UPDATE: Wrapped in WP-friendly jQuery no-conflict code...

  • Okay now, this part works, but somehow override the CSS and therefore the content of shrinking – Szántai Ádám Oct 5 '13 at 16:05
  • Any idea why it's doing this? – Szántai Ádám Oct 5 '13 at 16:09
  • Yes. That's because it's filling #content with #content - you'll need to either change what new.php outputs (and get rid of the wrapping #content div), or change load with the parent. – murdaugh Oct 5 '13 at 16:10
  • I'm verry new bie in programing,can you share with me the script? – Szántai Ádám Oct 5 '13 at 16:14
  • That makes things a little tricky, but let's try (immediately after your jQuery load line in the script) $("#content1 article").unwrap(); and see if that fixes things. – murdaugh Oct 5 '13 at 16:33

WordPress loads jQuery in NoConflict mode.

Do not use $. Use jQuery or one of the other solutions in the Codex, like this one:

(function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut

Nothing will work until you sort that out.

  • Not sure I agree with "nothing will work until you sort that out" but it's certainly the best practice - updated my answer to reflect that note. – murdaugh Oct 5 '13 at 16:02
  • Unless you've loaded your own jQuery, or manipulated/added the $ object in some way, the jQuery dependent Javascript will not work. You will get a ReferenceError: $ is not defined. I am not sure what's not to agree with. – s_ha_dum Oct 5 '13 at 16:08
  • Correct. And I'm not condoning the practice of short circuiting WP's jQuery behaviors, but that doesn't mean it's not reasonably common practice and - in fact - in this case it was. – murdaugh Oct 5 '13 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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