简体   繁体   English

从管理面板更改WordPress中的类别名称需要更改代码

[英]changing category name in WordPress from admin panel requires changing in codes

I'm developing a theme for WordPress, so to show posts from specific category I used wp_query() function to specify the category. 我正在为WordPress开发主题,因此为了显示特定类别的帖子,我使用了wp_query()函数来指定类别。 like this: 像这样:

 $slogan = new wp_query(
                        array(
                                'category_name' => "hero_slider",
                                'title' => "slogan"
                            )
                    );

so when I rename the hero_slider category from admin panel there is need to change this code in the file to update category name. 因此,当我从管理面板重命名hero_slider类别时,需要在文件中更改此代码以更新类别名称。
please help me how to show posts in a theme so that the changing category names don't need to changing the code. 请帮助我如何显示主题中的帖子,以使更改类别名称无需更改代码。 thanks! 谢谢!

Use the category id,its unique, doesn't alter if you modify the category :) 使用类别ID,它是唯一的,如果您修改类别,则不会改变:)

array(
'cat'   => $cat_id,
'title' => "slogan"
)

Use the category id, for reference visit Link 使用类别ID,以供参考访问链接

or change to this as shown above by madalinivascu array( 'cat' => $cat_id, 'title' => "slogan" ) 或通过madalinivascu array( 'cat' => $cat_id, 'title' => "slogan" )更改,如上所示

Hope it helps 希望能帮助到你

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

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