简体   繁体   English

如何将类别 ID 放入 href 链接中(php、wordpress)

[英]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.我有一个 href 链接,我想将其重定向到我创建的类别。

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

my category name: osten & my category id: 43我的类别名称:osten & 我的类别 ID:43

You can use get_term_link https://developer.wordpress.org/reference/functions/get_term_link/ .您可以使用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.为此,如果您有 ID,则可以将其传递给那个 function。
Check the documentation for this function and see what argument you can pass it检查这个 function 的文档,看看你可以传递什么参数

Maybe this can help?也许这可以帮助? You can pass either name or ID您可以传递名称或 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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