I want to load the new entries without reloading the page.
I found a great solution for:
The ajax script:
<script>
$(document).ready(function() {
var refreshId = setInterval(function()
{
$('#content').fadeOut("fast").load('http://neocsatblog.mblx.hu/new.php').fadeIn("fast");
}, 10000);
});
</script>
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'); ?>
</div>
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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Try changing your script to this since you’re not actually running a cross-browser request:
<script>
(function($) {
$(document).ready(function() {
var refreshId = setInterval(function()
{
$('#content').fadeOut("fast").load('/new.php').fadeIn("fast");
$("#content .span9 article").unwrap();
}, 10000);
});
})(jQuery);
UPDATE: Wrapped in WP-friendly jQuery no-conflict code…
Method 2
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
})(jQuery);
Nothing will work until you sort that out.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0