admin管理员组

文章数量:1291491

This question already exists: Php string not working in Wordpress Functions.php (trying to fetch 1st category for each blog that post appears in the sidebar) Closed 3 years ago.

How to pass the following code.

<div> <?php $category = get_the_category(); ?>
      <a  href="<?php echo get_category_link($category[0]->cat_ID); ?> ">
      <?php echo $category[0]->cat_name; ?> </a>
</div>

In the function.php file's following code.

$related_blog .="//want to pass the above code here.";

For detailed description visit here: click here

This question already exists: Php string not working in Wordpress Functions.php (trying to fetch 1st category for each blog that post appears in the sidebar) Closed 3 years ago.

How to pass the following code.

<div> <?php $category = get_the_category(); ?>
      <a  href="<?php echo get_category_link($category[0]->cat_ID); ?> ">
      <?php echo $category[0]->cat_name; ?> </a>
</div>

In the function.php file's following code.

$related_blog .="//want to pass the above code here.";

For detailed description visit here: click here

Share Improve this question asked May 28, 2021 at 12:19 rt5277rt5277 12 bronze badges 1
  • If your question does not get much attention, you should improve it by editing it so that it's clearer and easier to understand, do not repost it as a new duplicate question – Tom J Nowell Commented May 28, 2021 at 13:02
Add a comment  | 

1 Answer 1

Reset to default 0

You can use below code to append the string:

<?php
$category = get_the_category();
$related_blog .= '<div><a  href="'. get_category_link($category[0]->cat_ID). '">'. $category[0]->cat_name.' </a></div>';
?>

本文标签: Php string not working in Wordpress Functionsphp