I have a small php code. This code get the title’s of the blog items. But i have a question about this code.
How can I make it. That pick-up of last 6 titles?
<ul class="blog-list">
<?php foreach ($siblings as $sibling) : ?>
<li><a href="<?php echo get_permalink($sibling->ID); ?>" data-nav-position="fade"><?php echo get_the_title($sibling->ID); ?></a></li>
<?php endforeach; ?>
</ul>
Thanks for help
Easiest option with not many changes in your.
If you take some of elements of array do not use
foreach
(see the word each?).Use
for
loop insteadto get first 6 or
to get last six (in reverse order)
EDIT
This won’t work if array keys are not integers or have some empty ranges in it. You may then use
array_slice()
as suggested in other answer orarray_pop()
six times.use array_slice to get last six items and then loop through it.