如何在PHP中获取?我试图解决这个问题失去了2天。请求帮助 描述图片在这里......
这是我的代码。我真的不知道如何解决这个问题。
<?php /*----------------------- predelava --------------------------*/ ?>
<?php $temp_query = $wp_query; ?>
<?php query_posts('cat=7&showposts=5'); //'cat=1 <-- Tukaj vpiši id tvoje kategorije ?>
<?php $numposts = $wp_query->post_count; ?>
<?php while (have_posts()) : the_post(); ?>
<div class='<?php echo (++$j % 2 == 0) ? 'evenpost' : 'oddpost'; ?>'>
<?php if ($j != $numposts){
the_content();
}
?>
</div>
<?php if($numposts %2 == 0 && $j == $numposts)
{
?>
<div class="center">
<?php the_content(); ?>
</div>
<?php // class "center" definiraj v css fajlu tako da bo pozicioniran kot želiš ;)
}
?>
<?php endwhile;?>
<?php $wp_query = $temp_query; ?>
我也这样试过:
<?php
/*----------------------- predelava --------------------------*/
$temp_query = $wp_query; ?>
<?php query_posts('cat=7&showposts=5'); //'cat=1 <-- Tukaj vpiši id tvoje kategorije ?>
<?php $numposts = $wp_query->post_count; ?>
<?php while (have_posts()) : the_post(); ?>
<div class='<?php echo (++$j % 2 == 0) ? 'evenpost' : 'oddpost'; ?>'>
<?php if ($j != $numposts){
the_content();
} ?></div>
<?php if($numposts %2 != 0 && $j == $numposts)
{
?><div class="center"><?php the_content(); ?></div> <?php // class "center" definiraj v css fajlu tako da bo pozicioniran kot želiš ;)
}
?>
<?php endwhile; ?>
<?php $wp_query = $temp_query; ?>
</div>
来自斯洛文尼亚的问候
答案 0 :(得分:0)
我的朋友帮助了我:)。
他这样做了:
<?php
/*----------------------- predelava --------------------------*/
$temp_query = $wp_query; ?>
<?php query_posts('cat=7&showposts=5'); //'cat=1 <-- Tukaj vpiši id tvoje kategorije ?>
<?php $numposts = $wp_query->post_count; ?>
<?php
$i = 1;
while (have_posts()) : the_post();
if($i %2 != 0)
{
if($i == $numposts)
{
echo "<div class='center'>";
the_content();
echo '</div>';
}else
{
echo "<div class='evenpost'>";
the_content();
echo '</div>';
}
}
else
{
echo "<div class='evenpost'>";
the_content();
echo '</div>';
}
$i++;
?>
<?php endwhile; ?>
<?php $wp_query = $temp_query; ?>
&#13;
现在它正常运作。感谢