我已经设置了一个wordpress网站,它加载一个初始页面,然后使用jquery .load来抓取其他php页面 . 这些页面最初是在wordpress中创建的,其中php包含相应的文本.php文件 .

因此,网站加载其 Headers 一次,然后使用.load创建和删除DOM元素 . 我现在正处于设置网站博客以显示wordpress帖子的位置 . 我创建了一个小循环,通过帖子 . 当我通过example.com/myLoop打开循环时,它可以工作,但是当我通过指向它的.php文件加载它时,我得到一个php错误“调用未定义的函数get_posts()” .

<div id="postsContainer">
    <?php
    global $post;
    $args = array( 'numberposts' => 100 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
        <div class="postBody">
        <h1 class="postTitle"><?php the_title(); ?></h1>
            <?php the_content(); ?>
            <div class="postAttachment">
            <?php
            //display image attachments
            $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); 
            $attachments = get_posts($args);
            if ($attachments) {
                foreach ( $attachments as $attachment ) {
                    //echo apply_filters('testies', $attachment->post_title );
                    //echo "help me";
                }



            }
            ?>
            </div>
            <p class="postInfo">Posted by <?php $author = get_the_author(); echo $author . ', '; the_date(); ?></p>
            <div class="socialButtons">
            <a class="" href="mailto:type email address here?subject=I want to share this post with you from <?php bloginfo('name'); ?>&body=<?php the_title('','',true); ?>:&#32;&#13;<?php the_permalink(); ?>" title="Email to a friend" target="_blank">email this  |</a>
            <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink() ?>">  share on facebook  |</a>
            <a href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php the_permalink() ?>">  share on google+  |</a>
            <a href="https://twitter.com/share?url=<?php the_permalink() ?>">  tweet</a>
            </div>

        </div>      
    <?php endforeach; ?>
    </div>