2013-07-24 16 views
0

你們都。從Wordpress循環獲取正確的回報

因此,我試圖讓我們的WordPress博客在我們基於HTML的網站的不同頁面上展示。我做了大量的研究,我有一個很好的想法,我應該如何繼續(我認爲),但我不認爲我拉動正確的Loop代碼來做到這一點。

的頁面是在這裏:www.cidermag.com/blog.php

正如你可以看到,該網站會返回「一無所獲」的值,即使我們有大約三四個測試樁已通過公佈WP儀表板。但是,我得到了Loop的這一部分返回的事實給了我希望我在正確的軌道上......

根據我在網上找到的說明,我從index.php中提取循環代碼文件位於我們的/ blog/wp-content/themes/twentytwelve文件夾中。我知道我必須爲特定的事物編制具體的價值觀,但我現在只需要至少讓博客展示,所以我有一個理解這個野獸的起點。 (我的學習效果比閱讀好。)

任何援助將不勝感激,因爲我似乎無法找到明確的答案。謝謝!

的循環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 ?> 
+0

請張貼一些培訓相關的PHP代碼,以幫助您與您的問題 – Schleis

+0

你的博客的網址是什麼? http://cidermag.com/blog/?我在那裏看到帖子。你有沒有設置主題?爲什麼你給我們的URL以.php結尾? –

+0

/博客是我們安裝WP(每條指令)的位置。但是,因爲這不是一個WP網站,所以我們讀的所有內容都需要用.php擴展名重命名HTML頁面。因此頁面的URL。我們沒有設定任何主題,因爲訪問者的最終目標是永遠不會看到WP默認頁面 - 只有我們HTML網站上的帖子。 – user2612650

回答

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(); ?> 
+0

爲什麼「一個壞主意」?整個網站上都有網站正在做我們正在嘗試做的事情 - 將PHP調用集成到html網站中。不同的是,我們只是不知道該怎麼做。順便說一句,我非常感謝你的幫助 - 只是試圖讓你的想法得到一些背景...... WP實際上給出瞭如何做這個動作的指導(參考:http://codex.wordpress.org/Integrating_WordPress_with_Your_Website),但我的主題中的循環代碼只調用「Nothing Found」操作。所以我想我的根本問題應該是:我在哪裏可以找到適合我們主題的完整循環代碼? – user2612650

+0

你在我的答案中找到它。 –

+0

好的,感謝您的幫助 - 我們不想將我們的整個網站從屬於WP,所以我們會找到解決方案。再次感謝你! – user2612650