2013-03-29 56 views
0

因此,我需要计算为某个组拉入了多少个条目。继承人我的代码虚弱了下来。表达式引擎在循环中计数条目

<?php $i = 0; ?> 
{exp:weblog:entries related_categories_mode="on" custom_fields="on" orderby="view_count_one" sort="desc" limit="4" offset="0" weblog="{my_weblog1}" start_on="<?php echo $current_time; ?>" } 

     <table> 
     <tr valign="top" style="margin-bottom:10px;"> 
      <td> {if weblog == "Newsroom"} <a href="{title_permalink="freedom/articles}">{if Image}<img src="{Image}" >{/if}</a> 
      {if:elseif weblog == "Health Freedom"} <a href="{title_permalink="freedom/articles}">{if Image}<img src="{Image}" >{/if}</a> 
      {/if} <br /></td> 
      <td> <h3>{if weblog == "Newsroom"} <a href="{title_permalink="freedom/articles}">{title}</a> 
      {if:elseif weblog == "Health Freedom"} <a href="{title_permalink="freedom/articles}">{title}</a> 

      {/if} <span class="date">&ndash; {entry_date format='%m/%d/%Y '} </span> </h3> 

</td> 
     </tr> 
<?php $i = $i++; ?> 
     <?php $count = '{count}'; ?> 
<?php echo $count;?> {/exp:weblog:entries} 
<?php echo $count; ?> 
<?php echo $i; ?> 

它计数到4 $计数在循环过程因此,基本上,但ontside的博客我得到$数1和0 $我。有人能帮我吗?我还应该提到php正在输入中呈现。谢谢!

回答

0

变化

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

<?php $i++; ?> 

你的方式是新$i设置为老$i,然后递增老$i(不再存在)。

+0

我仍然只得到1的问题是PHP是博客圈之前被渲染。但是仍然用我的$ count变量得到了4的计数,但是一旦我把它拿出来循环,我就得到1.它只在循环中看到它并接受它...是否有某种方式可以设置变量只在最后一次迭代? – Trey

+0

用'$ count'检查我的编辑。第一部分是'$ i'。 – MichaelRushton

+0

或以某种方式使该PHP变量被推迟到ee代码被渲染之后? – Trey