简体   繁体   中英

How to put category ID inside a href link ( php, wordpress )

I have a link with a href which i want to redirect me to category i created.

EX: <a href="/page/category/">Button</a>

my category name: osten & my category id: 43

You can use get_term_link https://developer.wordpress.org/reference/functions/get_term_link/ .
For that, if you have the ID, then you can pass it to that function.
Check the documentation for this function and see what argument you can pass it

Maybe this can help? You can pass either name or ID

<?php
    // Get the ID of a given category
    $category_id = get_cat_ID( 'Category Name' );

    // Get the URL of this category
    $category_link = get_category_link( $category_id );
?>

<!-- Print a link to this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM