• I apologize for the uninformative title.

    I have set up a php file to simply feed post titles into javascript. Actually, I’ve set up 3 of them. On 2 of the blogs, it works fine. On the other, however, it does not find any posts. Here is the basic code:

    <?php require_once('wp-blog-header.php');
    
    while (have_posts()) : the_post(); ?>
    
    document.write("<a href='<?php the_permalink() ?>'><?php the_title(); ?></a>");
    
    <?php endwhile; ?>

    You can see it working here.

    You can see it not working here. (I tested it with an if loop, which returned “nothing found”.)

    Now it happens that on our site’s index page, there is another headline feed, which I adapted for the javascript output:

    <?php require_once('wp-blog-header.php'); ?>
    
    <?php $posts = get_posts('numberposts=10&order=DESC&orderby=post_date');
    foreach ($posts as $post) : start_wp(); ?>
    
    document.write("<a href='<?php the_permalink() ?>'><?php the_title(); ?></a>");
    
    <?php endforeach;  ?>

    That works. What could be preventing the original loop code, which works for 2 of the blogs, fail with the 3rd blog?

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

    (@ericr23)

    That last sentence should read, What could be preventing the original loop code, which works for 2 of the blogs, from working with the 3rd blog?

    Thread Starter ericr23

    (@ericr23)

    The link to show it not working is now using the get_posts() code, so it is working. The link to show it working is still using the loop code. If you want to see the loop code not working, insert the following into a page:

    <script language="JavaScript" src="https://www.wind-watch.org/documents/jsfeed.php" />
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Strange loop failure’ is closed to new replies.