2016-09-21 70 views
0
頭版

因此,這裏是讓一個英雄出現在我的WordPress網站的博客節(當我填充一個自定義後類型,稱爲「介紹」)的代碼:變化Wp_query參數傳遞給

<?php 
$args = array('post_type' => 'intro', 'posts_per_page' => 1); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); ?> 

---more code here--- 

<?php endwhile; ?> 

我在想什麼,如果有的話,我可以在第二行中改變,以使效果發生在我選擇的任何頁面上作爲主頁。

感謝

編輯1:

<?php /* Template Name: eFrontpage */ ?> 

<?php 
$args = array('post_type' => 'intro', 'posts_per_page' => 1); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); ?> 

<div class="point-1"></div> 


<div class="home-intro" style="background-image: url(<?php 
the_field('background-image'); ?>)"> 

<div class="home-intro-inside"> 
    <h1 class="<?php the_field('intro_text_color'); ?>"> 
<?php the_field('intro-text'); ?> 
</h1> 
<a class="scroll-down <?php the_field('button_text_color'); ?>" 
style="background-color: <?php the_field('button-background-color'); 
?>"> 
<?php the_field('button-text'); ?> 
    </a> 
    </div> 
    </div> 

<div class="space"></div> 

<script> 


jQuery("body").addClass("intro-is"); 


</script> 

<?php get_header(); ?> 

    <div id="primary" class="content-area container"> 
    <main id="main" class="site-main" role="main"> 

     <?php while (have_posts()) : the_post(); ?> 

      <?php get_template_part('content', 'page'); ?> 




      <?php 
       // If comments are open or we have at least one comment, load up the comment template 
       if (comments_open() || '0' != get_comments_number()) : 
        comments_template(); 
       endif; 
      ?> 

     <?php endwhile; // end of the loop. ?> 

    </main><!-- #main --> 
</div><!-- #primary --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 
+0

我不是很確定你想要什麼,但是如果你想要這個代碼只是爲了首頁,你可以將這段代碼放在front-page.php –

回答

0

你不需要有任何改變。您需要將創建英雄部分的循環複製到您的首頁模板代碼中。它可能無法正常工作,取決於樣式化英雄部分的CSS。

您還應該確保您使用的是子主題,而不是覆蓋原來的主題。

+0

我爲首頁創建了一個新的頁面模板並添加了英雄進入模板的代碼,但我收到以下錯誤:「解析錯誤:語法錯誤,意外的文件結尾...」 – eddie2000

+0

錯誤說什麼? – Fencer04

+0

我編輯了上面的註釋以包含錯誤 – eddie2000