【发布时间】:2016-09-21 18:43:16
【问题描述】:
下面是使英雄出现在我的 wordpress 网站的博客部分的代码(当我填充名为“intro”的自定义帖子类型时):
<?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中
标签: php wordpress html customization