因此,這裏是讓一個英雄出現在我的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(); ?>
我不是很確定你想要什麼,但是如果你想要這個代碼只是爲了首頁,你可以將這段代碼放在front-page.php –