1
我已经制作了一个包含四个不同类别的主页来显示。我认为它运行良好,但现在所有帖子都与第一篇文章有相同的内容。链接和精选图片都很好,但文本以某种方式被覆盖。wordpress发布内容重复
Heress屏幕上的所有文本都是相同的:
http://imagizer.imageshack.us/v2/800x600q90/713/m1j6.jpg
编辑:所以这一点也适用<?php setup_postdata($post); ?>
内循环
我的代码:
<div class="bmw">
<h2>bmw news</h2>
<?php $k = 1;
$posts = get_posts('category=7&orderby=date&numberposts=2'); foreach($posts as $post) { ?>
<?php setup_postdata($post); ?>
<div id="home_post<?php if($k%2 == 0) echo "last" ;?>">
<?php if (has_post_thumbnail()) {?>
<a href="<?php the_permalink() ?>"><div id="img">
<span>
<?php the_post_thumbnail(); ?>
</span>
</div>
</a>
<?php }; ?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<span id="tags"><?php the_tags(); ?></span>
<?php the_content('...'); ?>
<div class="button_more"><a href="<?php the_permalink() ?>">Czytaj więcej<span><img style="vertical-align:middle;width:auto;margin-left:5%" src="http://test.startujac.pl/images/strzalka_czytaj_wiecej.png"></span></a></div>
</div>
<?php $k++; ?>
<?php } ?>
</div>
<div class="news">
<h2>VW news</h2>
<?php $v = 1;
$posts = get_posts('category=12&orderby=date&numberposts=2'); foreach($posts as $post) { ?>
<?php setup_postdata($post); ?>
<div id="home_post<?php if($v%2 == 0) echo "last" ;?>">
<?php if (has_post_thumbnail()) {?>
<a href="<?php the_permalink() ?>"><div id="img">
<span>
<?php the_post_thumbnail(); ?>
</span>
</div></a>
<?php } ?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<span id="tags"><?php the_tags(); ?></span>
<?php the_content('...'); ?>
<div class="button_more"><a href="<?php the_permalink() ?>">Czytaj więcej<span><img style="vertical-align:middle;width:auto;margin-left:5%" src="http://test.startujac.pl/images/strzalka_czytaj_wiecej.png"></span></a></div>
</div>
<?php $v++; ?>
<?php }?>
</div>
<div class="japan">
<h2>japan news</h2>
<?php $k = 1;
$posts = get_posts('category=13&orderby=date&numberposts=2'); foreach($posts as $post) { ?>
<?php setup_postdata($post); ?>
<div id="home_post<?php if($k%2 == 0) echo "last" ;?>">
<?php if (has_post_thumbnail()) {?>
<a href="<?php the_permalink() ?>"><div id="img">
<span>
<?php the_post_thumbnail(); ?>
</span>
</div></a>
<?php } ?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<span id="tags"><?php the_tags(); ?></span>
<?php the_content('...'); ?>
<div class="button_more"><a href="<?php the_permalink() ?>">Czytaj więcej<span><img style="vertical-align:middle;width:auto;margin-left:5%" src="http://test.startujac.pl/images/strzalka_czytaj_wiecej.png"></span></a></div>
</div>
<?php $k++; ?>
<?php } ?>
</div>
<div class="events">
<h2>imprezy i zloty</h2>
<?php $k = 1;
$posts = get_posts('category=1&orderby=date&numberposts=4'); foreach($posts as $post) { ?>
<?php setup_postdata($post); ?>
<div id="home_post<?php if($k == 1) echo "first" ;?>">
<?php if (has_post_thumbnail()) {?>
<div id="img">
<span>
<?php the_post_thumbnail(); ?>
</span>
</div>
<?php } ?>
<div id="content">
<h3><?php the_title(); ?></h3>
<span id="tags"><?php the_tags(); ?></span>
<?php the_content('...'); ?>
</div>
</div>
<?php $k++; ?>
<?php } ?>
</div>
不,我没有,但你的意思是什么,完全;)?我在index.php文件中得到了这段代码。那么,我把它放在哪里?在'<?php'或以下? –
你需要把它放在这样的PHP标签中:'<?php the_post();'。 –
但在包含我上面提供的代码的文件中,对不对?或其他模板文件?我补充说,但没有任何改变。 –