Php 首先发布不同的布局

Php 首先发布不同的布局,php,wordpress,formatting,conditional,Php,Wordpress,Formatting,Conditional,我需要有一个不同的布局,在每一页的第一篇文章,但不知道从哪里开始。代码如下: <?php get_header(); ?> <div class="row"> <section class="small-12 columns grid-style"> <?php $i = 0; $counter = range(0, 200, 3); ?> <?php $paged = get_query_var( 'paged' ) ? get

我需要有一个不同的布局,在每一页的第一篇文章,但不知道从哪里开始。代码如下:

<?php get_header(); ?>
<div class="row">
<section class="small-12 columns grid-style">
<?php $i = 0; $counter = range(0, 200, 3); ?>

  <?php 
  $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
  $args = array('offset'=> 0, 'paged'=>$paged);
  $all_posts = new WP_Query($args);
  if (have_posts()) :  while($all_posts->have_posts()) : $all_posts->the_post();?>

    <?php if ($i % 3 == 0) { echo '<div class="row journal" data-equal=".post">'; } ?

    <!--Post -->
      <article class="grid-style post" id="post-<?php the_ID(); ?>"
        <div class="post-img">
            <?php get_template_part( 'inc/postformats/grid-style' ); ?>
        </div>
        <div class="post-box">
            <div class="post-title">
                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo ShortenText(get_the_title(), 50); ?></a></h2>
            </div>
            <aside class="post_categories">
                                <?php the_category(', '); ?>
            </aside>
            <div class="post-content">
                <?php echo ShortenText(get_the_excerpt(), 170); ?>
            </div>
        </div>
      </article>

    <!--/Post -->

      <?php if (in_array($i + 1, $counter)){ echo '</div>'; }   ?>

  <?php $i++; endwhile; ?>

    <div class="small-12 columns">
      <?php theme_pagination($all_posts->max_num_pages, 1, true); ?>
    </div>
  <?php else : ?>
    <p><?php _e( 'Please add posts from your WordPress admin page.', THB_THEME_NAME ); ?></p>
  <?php endif; ?>
</section>
</div>
<?php get_footer(); ?>   


我需要使用不同的图像大小,因此我需要输出<!--Post->仅针对第一篇文章再次发布。

是否尝试将div.row.journal包含到第一篇文章中? 如果是这种情况,请尝试这样做:


替换
您必须定义一个计数器并用if…else。。。圈内

$post_counter = 1;
while (start_loop):

   if ($post_counter == 1){
       echo "<div id='1'></div>";
   else:
       echo "<div id='2'></div>";

   $post_counter += 1;

//end loop
$post\u计数器=1;
while(启动循环):
如果($post_计数器==1){
回声“;
其他:
回声“;
$post_counter+=1;
//端环

我想这应该会对你有所帮助。

这是我现在的代码,我可以为第一篇文章输出HTML,为所有文章输出一个不同的HTML,但我得到了两篇第一篇文章。一篇使用第一个布局,第二篇使用第二个布局


1.


Hi@plop谢谢你的帮助!这对第一篇文章中的广告类非常有效。但我正在尝试的是有一个完全不同的布局和更大的图像,所以我需要再次回显里面的所有内容,但我很难弄清楚如何使用类似的东西来实现这一点?
并在中复制文件c/postformats/grid-style.php转换为inc/postformats/other-layout-style.php,然后通过编辑other-layout-style.php,您将能够完成您想要的布局。感谢@Tobi Klostermair没有真正起作用,可能是因为我不懂php。但让我想到$post_counter=1/我实际上需要做的是使用$post_count=0,然后使用$post_counter++;当它达到1时,输出我想要的html,但现在我有2份第一篇文章的副本…关于如何只输出1篇第一篇文章,有什么想法吗?我会自己回答,这样你就可以看到我现在使用的代码
<?php
if ($all_posts->current_post == 0 && !is_paged()) {
    echo '</div>';
}
?>
$post_counter = 1;
while (start_loop):

   if ($post_counter == 1){
       echo "<div id='1'></div>";
   else:
       echo "<div id='2'></div>";

   $post_counter += 1;

//end loop