简体   繁体   中英

trying to use query_posts('category_name=page_slug');

I´m trying to query posts after category name and want the ('category_name= cat-name '); cat-name to be taken from the page title, lets say the page title is "Forename Lastname" then the perma-link will be /forename-lastname/ . Is it possible to make the cat-name copy the "forname-lastname" with php or must I try to make some a javascript to take care of it?

The "permalink" of the page it's stored as its post_name , so you can get it from the global $post

For instance:

global $post;
$slug = $post->post_name;
$posts_in_cat = query_posts('category_name='. $slug );

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