지난 5 시간 동안 내 머리를 찢어 내고 있습니다. 특정 분류에서 내 맞춤 게시물을 표시하고 페이지 템플릿에서 실행중인 코드를 여러 루프로 사용하려고하지만 제목, 발췌 및 영구 링크가 페이지 자체를 가리키며 내 맞춤 게시물이 아닙니다. 루프.사용자 정의 포스트 루프가 올바른 정보를 표시하지 않는 페이지 템플릿
- 나는 올바른 게시물이
get_posts($args)
에서 반환되는 여부를 확인하기 위해 내 함수 내에서print_r($posts)
를 사용, 그것은 등 게시물과 콘텐츠의 제목, 즉 올바른 정보를 보여줍니다은 무엇 혼란 것은이다
- 게시물의 번이 표시됩니다.
- 게시물이없는 경우
if(have_posts($posts))
에 아무 것도 표시되지 않습니다.
마치 페이지 템플릿의 ID가 내 사용자 정의 루프를 덮어 쓰는 것처럼 보입니다. 완전히 루피하기 전에 문제가 무엇인지 알 수 있습니까?
감사
오스
/* ****************************************************************** */
/* !BOX LAYOUT */
/* ****************************************************************** */
// Function to create boxes
function osu_fbox($day, $cpt, $tax, $term) {
// Filter posts
$args = array(
'post_type' => $cpt,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term
)
)
);
$posts = get_posts($args);
print_r($posts);
// Display content for this box
echo '<p class="fheading">' . $day .'</p>';
if (have_posts($posts)) :
foreach ($posts as $post) : setup_postdata($post); ?>
<div id="lk-<?php echo sanitize_title($day); ?>-post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'literarykitchen'), the_title_attribute('echo=0')); ?>" rel="bookmark" class="readmore"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'literarykitchen'), the_title_attribute('echo=0')); ?>" rel="bookmark" class="readmore">Read more...</a>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No festival items currently scheduled</p>
<?php endif; wp_reset_query(); // Reset query so we can go again
}
// ------------------------------------------------------------------
// // !BOXES
// ------------------------------------------------------------------
// CPT and taxonomy
$cpt = 'lkfestival';
$tax = 'lkdays';
// Start if password protected
if (post_password_required()) : ?>
<p>We are currently working on the festivals area.</p>
<p>Please check back soon</p>
<?php echo get_the_password_form(); ?>
<?php else: ?>
<div id="weekdays" class="fcol">
<?php echo osu_fbox('Monday', $cpt, $tax, 'monday'); ?>
<?php echo osu_fbox('Tuesday', $cpt, $tax, 'tuesday'); ?>
<?php echo osu_fbox('Wednesday', $cpt, $tax, 'wednesday'); ?>
<?php echo osu_fbox('Thursday', $cpt, $tax, 'thursday'); ?>
<?php echo osu_fbox('Friday', $cpt, $tax, 'friday'); ?>
</div> <!-- End #weekdays -->
<div id="saturday" class="fcol">
<?php echo osu_fbox('Saturday', $cpt, $tax, 'saturday'); ?>
</div> <!-- End #saturday -->
<div id="sunday" class="fcol">
<?php echo osu_fbox('Sunday', $cpt, $tax, 'sunday'); ?>
</div> <!-- End #sunday -->
<?php endif; /* End if post password protected */ ?>