我想表明我的主題爲WP的最後一篇文章,所以我寫了這個代碼:第一部分have_posts()返回false在WordPress
<?php get_header(); ?>
<div class="content">
<div class="pad group">
<?php get_template_part('inc/page-title'); ?>
<?php //echo var_dump(have_posts()); ?>
<?php if (have_posts()) : ?>
<?php if (ot_get_option('blog-standard') == 'on'): ?>
<?php while (have_posts()): the_post(); ?>
<?php get_template_part('content-standard'); ?>
<?php endwhile; ?>
<?php else: ?>
<div class="post-list group">
<?php $i = 1; echo '<div class="post-row">'; while (have_posts()): the_post(); ?>
<?php get_template_part('content'); ?>
<?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
</div><!--/.post-list-->
<?php endif; ?>
<?php get_template_part('inc/front-widgets-bottom'); ?>
<?php get_template_part('inc/pagination'); ?>
<?php get_template_part('inc/picks'); ?>
<?php endif; ?>
<?php get_template_part('inc/front-widgets-top'); ?>
</div><!--/.pad-->
我得到的標題,在content
股利我打開了一個名爲pad group
的容器,然後與page-title
我得到的頁面標題。
在這之後我檢查是否有可用的後(當然也有)有if (have_posts())
,但如果你看到我做的have_posts()
一個var_dump
,這回false
在條件代碼永遠不會執行,事實上。
我在這裏看到其他問題的同一主題,但我找不到任何解決方案。其中一些問題詢問if
條件未正確關閉,但我檢查了所有包含的文件(也包含header
),但我找不到任何問題。
有人可能比我有更好的眼睛?謝謝你的幫助。
功能'have_posts()'在檔案頁面模板可能工作...如果你使用的存檔頁面模板,確保文件的命名慣例符合標準...檢查'archive.php'文件中的代碼 –
@CrystalPaladin我忘了說這是index.php –
這些帖子是否正常WordPress的帖子?或者他們是自定義帖子? coz'have_posts()'只能用於普通的wordpress文章...並且檢查你的'functions.php'來檢查是否有任何篡改wp查詢的鉤子... –