Skip to content Skip to sidebar Skip to footer

Display Multiple Sets Of Content Items A From A Wordpress Query With Javascript

I am trying to get my recent posts to display in a fading content list with java-script. I want to pull 12 of the latest posts, and then display them, 4 at a time, from most recent

Solution 1:

<head>
<script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>

<div class="newsblock">

<ul id="newgall">
<?php
//display 10 posts with title and date
$args=array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'post_category' => '123',
  'posts_per_page' => 12,
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {

  while ($my_query->have_posts()) : $my_query->the_post(); 
?>

    <li>
    <p>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
    <br/><?php the_time('F jS, g:i a') ?>
    <br/>
    </p>
    </li>

    <?php
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>
  </ul>
</div>          
<script>
        var $items = $('#newgall li'),
            i = 0;

        function slide() {
            var index = i % $items.length;
            $items.hide().removeClass('curr').slice(index, index +4).show('fade').addClass('curr');
            i += 4;
            setTimeout(slide, 400);
        };

        slide();
</script>
    </body>

Make sure PHP is enabled though a plugin. This code works.


Post a Comment for "Display Multiple Sets Of Content Items A From A Wordpress Query With Javascript"