我成功地将此WP\\U查询加载到我的Wordpress模板全宽主页。php(第一页)文件:
模板全宽主页。php
<?php
/*
Template Name: Full Width (No Sidebar) Homepage
*/
get_header(); ?>
<div class="content">
<div class="homeSlider">
<div class="containerSlide">
<h1 class="headHead">Heading</h1>
</div>
</div>
<div class="inner-content grid-x grid-margin-x grid-padding-x home">
<main class="main small-12 medium-12 large-12 cell" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( \'parts/loop\', \'page\' ); ?>
<?php endwhile; endif; ?>
<div class="grid-x grid-padding-x blogsHome">
<?php
// the query
$the_query = new WP_Query( array(
\'posts_per_page\' => 3,
\'category_name\' => \'360 Themes!\'
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), \'thumbnail\' ); ?>
<div class="cell small-12 medium-6 large-4 singlePost">
<p><?php the_title(); ?></p>
<p><?php the_category(\', \'); ?></p>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<script>
console.log("loaded");
</script>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>
</div>
</main> <!-- end #main -->
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
WP_Query of template-full-width-home.php
<?php
// the query
$the_query = new WP_Query( array(
\'posts_per_page\' => 3,
\'category_name\' => \'360 Themes!\'
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query1->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), \'thumbnail\' ); ?>
<p><?php the_title(); ?></p>
<p><?php the_category(\', \'); ?></p>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>
但当我尝试将相同的WP\\u查询加载到另一个模板全宽主页时。php(第二页),我无法得到任何结果(没有像“第一页”那样加载任何内容)。如有任何见解,将不胜感激!
template-full-width-home-es.php
<?php
/*
Template Name: Full Width (No Sidebar) Homepage ES
*/
get_header(); ?>
<div class="content">
<div class="homeSlider">
<div class="containerSlide">
<h1 class="headHead">Heading</h1>
</div>
</div>
<div class="inner-content grid-x grid-margin-x grid-padding-x home">
<main class="main small-12 medium-12 large-12 cell" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( \'parts/loop\', \'page\' ); ?>
<?php endwhile; endif; ?>
<div class="grid-x grid-padding-x blogsHome">
<?php
// the query
$the_query1 = new WP_Query( array(
\'posts_per_page\' => 3,
\'category_name\' => \'360 Themes!\'
));
?>
<?php if ( $the_query1->have_posts() ) : ?>
<?php while ( $the_query1->have_posts() ) : $the_query1->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), \'thumbnail\' ); ?>
<div class="cell small-12 medium-6 large-4 singlePost">
<p><?php the_title(); ?></p>
<p><?php the_category(\', \'); ?></p>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<script>
console.log("loaded");
</script>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>
</div>
</main> <!-- end #main -->
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
WP\\U模板全宽主页查询。php模板
<?php
// the query
$the_query = new WP_Query( array(
\'posts_per_page\' => 3,
\'category_name\' => \'360 Themes!\'
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query1->the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), \'thumbnail\' ); ?>
<p><?php the_title(); ?></p>
<p><?php the_category(\', \'); ?></p>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __(\'No News\'); ?></p>
<?php endif; ?>