단일 게시물 모드 일 때 2 개의 최신 게시물을 반환하고 싶지만 현재 게시물은 제외하십시오. 그리고 나는 그것을했다. 문제는 단지 작동이 멈췄다는 것입니다. 그것은 코드를 변경하지 않았고 내 localhost뿐만 아니라 서버에서 멈추었습니다.wp_get_recent_posts가 작동을 멈췄습니다
<section id='recent_posts'>
<header class='recent_header'>
Recent posts
</header>
<?php
$id = $post->ID;
$recent_posts = wp_get_recent_posts("numberposts=2&exclude=$id");
foreach($recent_posts as $recent) { ?>
<article class='single_recent'>
<header>
<a href="<?php echo get_permalink($recent["ID"]); ?>"><?php echo $recent["post_title"]; ?></a>
</header>
<p>
<?php echo get_excerpt_by_id($recent["ID"]); ?>
</p>
</article>
<?php } ?>
</section>
사람이 설명이 있습니까 : 여기
코드인가?나는 인수를 제거하려고 시도했지만 아직 아무것도 시도하지 않았습니다. 빈 배열을 반환합니다.
동일한 효과를 얻기 위해 다른 기능을 사용해야하는 제안은 무엇입니까?
편집 :
<?php
get_header();
get_sidebar();
?>
<?php the_post() ?>
<article class='post-single'>
<header class='post_header'>
<h1><?php the_title(); ?></h1>
<div class='post_header_bottom'>
<strong class='post_category'><?php echo get_the_category_list(', '); ?></strong>
<strong class='post_author'><span class='symbol'>U</span> by <?php the_author(); ?></strong>
</div>
</header>
<?php if (has_post_thumbnail()) : ?>
<figure class='post_single_image'>
<?php the_post_thumbnail(); ?>
<figcaption>No Will No Skill</figcaption>
</figure>
<?php endif; ?>
<div class='post_perex'>
<?php the_content(); ?>
</div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime='<?php the_time('Y-m-d'); ?>' pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
<div class='post_share'>
<div class='share_show'>
<span class='symbol'>f</span> Like
|
<span class='symbol'>g</span> +1
|
<span class='symbol'>t</span> Tweet
<?php
if(function_exists('display_social4i'))
echo display_social4i("large","align-left");
?>
</div>
</div>
</footer>
</article>
<?php comments_template(); ?>
<section id='recent_posts'>
<header class='recent_header'>
Recent posts
</header>
<?php
global $post;
$id = $post->ID;
$qargs = array(
'post__not_in'=> array($id),
'posts_per_page' => 2
);
$recent_posts = new WP_Query($qargs);
if ($recent_posts->have_posts()) echo 'yes'; else echo 'nope';
if($recent_posts->have_posts()) : while($recent_posts->have_posts()) : $recent_posts->the_post(); ?>
<article class='single_recent'>
<header>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</header>
<p>
<?php the_excerpt(); ?>
</p>
</article>
<?php endwhile;endif; ?>
</section>
<div class='space'></div>
</div>
<?php
get_footer();
?>
단일 포스트 뷰에서 루프를 사용하는 이유는 무엇입니까? BTW에 게시 ID가 문제가되지 않습니다. 신분증이 잘 잡히네. 문제는 함수가 0 개의 게시물을 반환한다는 것입니다 (매개 변수 없이도) –
ID에 관계없이 함수가 여전히 결과 배열을 반환해야한다는 점이 맞습니다. 내 사과. 호기심에서 표준 게시물을 다루고 있습니까? 아니면 사용자 정의 게시물을 쿼리하려고합니까? 최근 맞춤 게시물 또는 페이지를 쿼리하려는 경우 'post_type'매개 변수를 설정해야하기 때문입니다. – maiorano84
예, 표준 게시물을 반환하고 싶습니다. 귀하의 코드를 시도하고 여전히 아무것도 반환하지 않습니다. 게시물을 편집하고 전체 single.php 코드를 붙여 넣으려고합니다. –