0

你们。

所以我试图让我们的 Wordpress 博客显示在我们基于 HTML 的网站的不同页面上。我做了很多研究,我很清楚我应该如何进行(我认为),但我认为我没有拉出正确的循环代码来做到这一点。

该页面在这里:www.cidermag.com/blog.php

如您所见,即使我们已经通过 WP Dashboard 发布了大约三四个测试帖子,该站点仍返回“Nothing Found”值。然而,我让 Loop 的那一部分返回的事实让我希望我走在正确的轨道上......

根据我在网上找到的说明,我从 /blog/wp-content/themes/twentytwelve 文件夹中的 index.php 文件中提取了循环代码。我知道我必须为特定的事物编写特定的值,但我至少需要立即显示博客,这样我就有了理解这个野兽的起点。(我通过做比通过阅读学得更好。)

任何帮助将不胜感激,因为我似乎无法找到明确的答案。谢谢!

循环php代码:

<?php require('blog/wp-blog-header.php'); ?>
                    <?php if ( have_posts() ) : ?>

        <?php /* Start the Loop */ ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>
        <?php endwhile; ?>

        <?php twentytwelve_content_nav( 'nav-below' ); ?>

    <?php else : ?>

        <article id="post-0" class="post no-results not-found">

        <?php if ( current_user_can( 'edit_posts' ) ) :
            // Show a different message to a logged-in user who can add posts.
        ?>
            <header class="entry-header">
                <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
            </header>

            <div class="entry-content">
                <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
            </div><!-- .entry-content -->

        <?php else :
            // Show the default message to everyone else.
        ?>
            <header class="entry-header">
                <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
            </header>

            <div class="entry-content">
                <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                <?php get_search_form(); ?>
            </div><!-- .entry-content -->
        <?php endif; // end current_user_can() check ?>

        </article><!-- #post-0 -->

    <?php endif; // end have_posts() check ?>
4

1 回答 1

0

这整件事似乎是一个非常糟糕的主意。我强烈建议您以正确的方式做事:创建一个主题,也许将您的整个网站放入 WordPress。

如果这是不可能的,您应该能够通过创建自定义查询来使其工作:

<?php
    $new_loop = new WP_Query( array(
    'post_type' => 'post',
        'posts_per_page' => -1 // this will display all available posts

    ) );
?>

<?php if ( $new_loop->have_posts() ) : while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?>

// your loop code

<?php endwhile; else: ?>

// your code for when no posts exists

<?php endif; ?>
<?php wp_reset_query(); ?>
于 2013-07-24T02:03:25.217 回答