• Deep breath…

    I have the following snippet of JS code…

    var fcontent=new Array();
    begintag='<div class="two">'; //set opening tag, such as font declarations
    </script>
    
    <script type="text/javascript">
    <?php query_posts('showposts=1&cat=5'); ?><?php while (have_posts()) : the_post(); ?>
    
    fcontent[0]='<img src="<?php $supporting_image=get_post_meta( $post->ID, 'thumbnail', true ); if (''!=$supporting_image) {  echo $supporting_image; } ?>" width="115" height="77" alt="" class="newspic" /><div class="calendarbit"><span class="day"><?php the_time('j'); ?></span><span class="month"><?php the_time('M'); ?></span></div><p class="titlebit"><?php the_title('<span style="font-weight:bold"><a href="/category/news">', '</a></span>'); ?><a href="/category/news"><img src="/images/news_icon.jpg" alt="" width="9" height="9" /></a></p>'
    
    <?php endwhile;?> 
    
    closetag='</div>';

    which works fine. It gets one post from the category, then stores all the data in the fcontent[0] element.

    But I wonder how I can select 3 Posts from my Query and then create a ‘fcontent’ array element for each.

    So you’d have:

    fcontent[0] = ‘news item 1 info’
    fcontent[1] = ‘news item 2 info’
    fcontent[2] = ‘news item 3 info’

    Is it easy to do this?

    Many thanks for any assistance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Is this a case for….WP-Advanced?

    I changed 'showposts=1&cat=5' to 'cat=5&showposts=' . $limit=3 . '' and now it shows 3 posts great!!

    But how do I then put each post content into an fcontent[] element ?

    So you’d have:

    fcontent[0] = ‘news item 1 info’
    fcontent[1] = ‘news item 2 info’
    fcontent[2] = ‘news item 3 info’

    Any ideas would be greatly appreciated. I’m tearing my hair out on this one.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    In case anyone is interested, managed to resolve it ??

    var fcontent=new Array();
    begintag='<div class="two">'; //set opening tag, such as font declarations
    </script>
    
    <?php query_posts('cat=5&showposts=' . $limit=3 . ''); ?><?php $i = 0; while (have_posts()) : the_post(); ?>
    <script type="text/javascript">
    fcontent[<?php echo $i;?>]='<img src="<?php $supporting_image=get_post_meta( $post->ID, 'thumbnail', true ); if (''!=$supporting_image) {  echo $supporting_image; } ?>" width="115" height="77" alt="" class="newspic" /><div class="calendarbit"><span class="day"><?php the_time('j'); ?></span><br /><span class="month"><?php the_time('M'); ?></span></div><p class="titlebit"><?php the_title('<span style="font-weight:bold"><a href="category/news">', '</a></span>'); ?><br /><?php the_content_rss('', TRUE, '', 10); ?><a href="category/news"><img src="images/news_icon.jpg" alt="" width="9" height="9" /></a></p>'
    </script>
    <?php $i++; ?>
    <?php endwhile;?>
    <script type="text/javascript">
    closetag='</div>';

    Thanks for taking a look!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Javascript / WP while loop issue…’ is closed to new replies.