【问题标题】:Change Wp_query args from blog to front page将 Wp_query 参数从博客更改为首页
【发布时间】: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


【解决方案1】:

您无需在此处进行任何更改。您需要将创建英雄部分的循环复制到您的首页模板代码中。根据设置 hero 部分样式的 CSS,它可能无法开箱即用。

您还应该确保您使用的是子主题,而不是覆盖您的原始主题。

【讨论】:

  • 我为首页创建了一个新的页面模板,并将英雄的代码添加到模板中,但我收到以下错误:“解析错误:语法错误,文件意外结束。 ..”
  • 说错了什么?
  • 超级新手……我贴在这里好吗?
  • 不,编辑您的问题并将其放在底部并附上解释。
猜你喜欢
  • 2018-10-26
  • 1970-01-01
  • 1970-01-01
  • 2020-06-26
  • 2023-03-14
  • 1970-01-01
  • 2017-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多