I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categories
$term_id = get_categories();
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
$categories = get_categories();
foreach($categories as $category) {
?>
<article>
<div class="poster">
<a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo '<img src="'.get_wp_term_image($category->term_id).'">' ?>
</div>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>
</div>
</article>
How would you exclude all subcategories?
Thank you
I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categories
$term_id = get_categories();
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
$categories = get_categories();
foreach($categories as $category) {
?>
<article>
<div class="poster">
<a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo '<img src="'.get_wp_term_image($category->term_id).'">' ?>
</div>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>
</div>
</article>
How would you exclude all subcategories?
Thank you
Share Improve this question asked Jun 13, 2019 at 13:41 juanjuan 12 bronze badges1 Answer
Reset to default 1$args = array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => 0
);
$categories = get_categories($args);
May this will help you. Refer this link
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745405084a4626279.html
评论列表(0条)