Very simple Question: Here is my get_categories()
code:
<?php $args = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 0,
'exclude' => '1',
'hierarchical' => 0,
'depth' => 1,
'number' => 12
);
?>
<?php $categories = get_categories( $args ); ?>
<div class="middle-left">
<ul>
<?php for( $i=0; $i<4; $i++ ) {
echo "<li>" . $categories[$i]->{'name'} . "</li>";
} ?>
</ul>
</div>
<div class="middle-middle">
<ul>
<?php for( $i=4; $i<8; $i++ ) {
echo "<li>" . $categories[$i]->{'name'} . "</li>";
} ?>
</ul>
</div>
<div class="middle-right">
<ul>
<?php for( $i=8; $i<12; $i++ ) {
echo "<li>" . $categories[$i]->{'name'} . "</li>";
} ?>
</ul>
</div>
After a long search I got the way how to get into the stdClass object without foreach loop and I want to proceed with this way. But I want only the top level categories, no subcats.
How can I modify the argument here?
Use
get_terms
with aparent
argument. From the Codex page for that function, emphasis mine:Untested, but this should do it.
Of course, you need to add any other arguments you require.
set
parent
to0
A native WordPress solution to return the CURRENT parent category.
You do not need to use foreach outside the function…
Comments: