admin管理员组文章数量:1410697
In WP_List_Table
, the method column_$custom( $item )
, if implemented, is called once for each row of data that is being displayed in the list table. So, if my list table has three rows of data, then the method column_$custom( $item )
will be called three times, once for each row
In addition to displaying the data, I need to know the "row index" of the data being displayed. In the above example, I like to extract 0
because it is the first row, 1
for the second, and 2
for the third. Is there a way of knowing the row index?
In WP_List_Table
, the method column_$custom( $item )
, if implemented, is called once for each row of data that is being displayed in the list table. So, if my list table has three rows of data, then the method column_$custom( $item )
will be called three times, once for each row
In addition to displaying the data, I need to know the "row index" of the data being displayed. In the above example, I like to extract 0
because it is the first row, 1
for the second, and 2
for the third. Is there a way of knowing the row index?
1 Answer
Reset to default 1That should be possible, but it looks pretty complicated. As you have undoubtedly seen, the display_rows
method just passes a single line and there's no counter. This means that the row number must be in the $item
variable for you to extract it. Since it is not there natively, you must insert it before you start displaying the table.
Luckily, there is a method expressly designed to do this, prepare_items
. This is an abstract class, meaning it must be filled in by child classes that use this class. Take, for instance, a look at the way it is implemented in WP_Posts_List_Table
.
So what you'll have to is override the existing prepare_items
of the child class you are working with, and loop through the rows to add a new property $row_count
to each one of them. Then, when you implement column_$custom( $item ) you can extract $row_count
.
Disclaimer: obviously I didn't test this myself, it's just a concept I think should work.
本文标签: wp list tableIndex of row in WPListTable
版权声明:本文标题:wp list table - Index of row in WP_List_Table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744883985a2630374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论