I added this code to display the category list in the wordpress post, it only displays text, no link, how to display the category link.
<?php
$args = array(
'type' => 'post',
'number' => 1,
'parent' =>
);
$categories = get_categories( $args );
foreach ( $categories as $category ) { ?>
<?php echo $category->name ; ?>
<?php } ?>
I added this code to display the category list in the wordpress post, it only displays text, no link, how to display the category link.
2
Answers
Oh my… Use get_category_link():
To augment what you’re doing you would simply get the category link before you echo the name and then close the link after the name, like this:
You also don’t need to keep opening and closing your PHP if you’re just going to keep running new lines of PHP (ie.
<?php ?>
)I got the basic gist of my answer from:
https://developer.wordpress.org/reference/functions/get_categories/
The documentation example is as follows:
The output is formatted different but it’s the same concept.