2017-06-14 57 views
0

我希望我的第一篇文章有​​不同的风格,并且位于当前文章的上方。我只喜欢在定制风格的设计中获得第一篇文章,其余的文章就像以前一样。顶帖宽度将为1188px。如果有人知道如何做到这一点,我会很高兴。谢谢。如何在wordpress页面上以不同格式显示第一篇文章?

下面是我想要的图片,第一张图片显示了当前情况,下一张图片显示了我想要实现的内容。

picture one picture two

我当前的PHP项目在这里:

<?php get_header(); ?> 
<!-- Begin Content --> 
<div id="content-a"> 

<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 
<div class="post"> 
<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div> 
<div class="p-heading"><h1><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div> 
<div class="p-content"> 
<?php the_excerpt(); ?> 
</div> 
<div class="p-info"><?php the_time('j.m.Y') ?> | <?php the_category(', '); ?> | <img src="http://www.virmodrosti.com/wp-content/uploads/comments.png" alt="Komentarji" width="26" height="12"><?php $totalcomments = get_comments_number(); echo $totalcomments; ?></div> 

</div> 

<?php endwhile; ?> 

<div class="navigation"> 
<div class="alignleft"><?php next_posts_link('Naslednja stran') ?></div> 
<div class="alignright"><?php previous_posts_link('Prejšnja stran') ?></div> 
<div class="clear"></div> 
</div> 

    <?php else : ?> 

</div> 
<div id="content"> 

<div class="post"> 
<div class="p-heading"><h1 class="center">Ni najdeno</h1></div> 
<div class="p-content"><p class="center">Oprostite, ampak iščete nekaj kar ni tukaj.</p> 
</div> 
</div> 
    <?php endif; ?> 

     </div> 

<!-- End Content --> 
<?php get_sidebar(); ?> 
<?php get_footer(); ?> 
+1

为什么不使用特定CSS样式仅定位在后列表中的第一个孩子?根本不需要担心循环中发生了什么。 – Korgrue

回答

1
<?php $i=1; ?> 
<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 
<?php if ($i == 1){ 

// here do the custom look you want to give to 1st post, i am sorry i dont know html 
<div class="post"> 
<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div> 
<div class="p-heading"><h1><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div> 
<div class="p-content"> 
<?php the_excerpt(); ?> 
</div> 
<div class="p-info"><?php the_time('j.m.Y') ?> | <?php the_category(', '); ?> | <img src="http://www.virmodrosti.com/wp-content/uploads/comments.png" alt="Komentarji" width="26" height="12"><?php $totalcomments = get_comments_number(); echo $totalcomments; ?></div> 

</div> 
<?php } else { ?> 

<div class="post"> 
<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div> 
<div class="p-heading"><h1><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div> 
<div class="p-content"> 
<?php the_excerpt(); ?> 
</div> 
<div class="p-info"><?php the_time('j.m.Y') ?> | <?php the_category(', '); ?> | <img src="http://www.virmodrosti.com/wp-content/uploads/comments.png" alt="Komentarji" width="26" height="12"><?php $totalcomments = get_comments_number(); echo $totalcomments; ?></div> 

</div> 
<?php } $i++; ?> 
<?php endwhile; ?> 
+0

太棒了!没有所有的复杂和不必要的东西!谢谢!你是个天才! – Techuser

+0

哈哈没有兄弟没有什么是天才,很高兴可以帮助你:) @Techuser – Exprator

+0

我有一个问题,也许你应该帮助我的第一篇文章。这篇文章需要他自己的div id =“content-big”包装,例如,而不是id =“content-a”,就像其他帖子一样。否则,它不能被移动到顶部,因为右侧边栏,我想删除div id =“content-a”,并用其他id替换为该帖子,但它不容易工作 – Techuser

相关问题