How to Loop within a Loop (Display Children and then Grandchildren)

Try something like: <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div class=”parent-post”> <?php the_title(‘<h2>’, ‘</h2>’); ?> <?php $children = new WP_Query( array(‘post_type’ => ‘page’, ‘post_parent’ => get_the_ID() )); ?> <?php if ( $children->have_posts() ) : ?> <ul class=”post-children”> <?php while ( $children->have_posts() ) : $children->the_post(); ?> <li><?php … Read more

Load comments per post on click with AJAX

Aha, I think my syntax was wrong. I changed: action: ‘do_ajax’, data: { ‘post_id’ : ’72’ //using a post id that I *know* has comments, for testing! }, to: data: { ‘action’ : ‘do_ajax’, ‘post_id’ : ’72’ }, and I’m getting the correct response from the console.log which shows: [{“comment_ID”:”1″,”comment_post_ID”:”1″,”comment_author”:”Mr WordPress”,”comment_author_email”:””,”comment_author_url”:”http:\/\/wordpress.org\/”,”comment_author_IP”:””,”comment_date”:”2012-08-28 19:55:20″,”comment_date_gmt”:”2012-08-28 19:55:20″,”comment_content”:”Hi, this is … Read more

Loop – how to get previous/next post for first/last post?

You can loop the slides quite simply: $prev_index = ( $loop->current_post == 0 ) ? count( $loop->posts ) – 1 : $loop->current_post – 1; $next_index = ( $loop->current_post == count( $loop->posts ) – 1 ) ? 0 : $loop->current_post + 1; $prev_post = $loop->posts[ $prev_index ]; $next_post = $loop->posts[ $next_index ]; echo $next_post->post_title; echo $next_post->post_title; … Read more

Add Infinite Scroll to Ajax Loaded Category Query

Update … Here’s the Final Code That Worked for Me This may not be perfect, but it seems to be working well for me with no errors. Feel free to add any suggestions for improvement if you have any. JS Code jQuery(document).ready(function($) { var count = 2; jQuery(“#la-chooser”).change(function() { loadArticlebyCat(this.value); }); function loadArticlebyCat(cat){ data = … Read more

Is it possible to display previous post revision?

First we look into the wp_get_post_autosave function It’s informative to see how the core function wp_get_post_autosave() uses the wp_get_post_revisions() function. It loops over all revisions from $revisions = wp_get_post_revisions( $post_id, array( ‘check_enabled’ => false ) ); and then uses: foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, “{$post_id}-autosave” ) ) … Read more

Ajax loop refresh on click

Shouldn’t be too tricky. First: create a javascript file and add this: jQuery(document).ready(function($){ $(‘#refresh-links-id’).click(function(e){ e.preventDefault(); $.post(ajaxurl,{action:’jpb_random_loop’}, function(data){ $(‘#content-inner’).fadeOut(250).empty().append( data ).fadeIn(250); }); }); }); Save that file in your theme directory somewhere (could be in a subdirectory too). For this to work, the refresh link should not be inside ul#content-inner. Pretty basic jQuery post call, though. … Read more

add_filter() doesn’t work in loop

It doesn’t work in your template because the query has already happened before the template is loaded. If you want to add your filter only under certain conditions, you need to hook an earlier action, like pre_get_posts, and check if the query is for the home page: function add_my_orderby_filter( $query ) { if ( $query->is_home … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)