开发者

Wordpress add_filter problem depending on permalinks setting

I wrapped code from this page: http://shibashake.com/wordpress-theme/add-tags-and-categories-to-your-wordpress-page into a Wordpress plugin, in order to allow adding categories and tags to WP pages.

It works with one exception - the filtering from the categories widget fails if my permalinks are set to default, e.g.

myblog.com/?cat=8

With a different permalink structure, e.g.

myblog.com/category/news 

all is开发者_如何学Go fine.

Here's the plugin code - how might I change the my_expanded_request function to accomodate all permalink types?

<?php
/**
 * @package Categories and Tags For Pages
 * @version 0.1
 */
/*
Plugin Name: Categories and Tags For Pages
Plugin URI: http://wordpress.org/#
Description: Expands category and tag options to include pages 
Author: Me
Version: 0.1
*/


function add_page_cats_and_tags() {
    register_taxonomy_for_object_type('post_tag', 'page');
    register_taxonomy_for_object_type('category', 'page');
}

add_action( 'admin_init', 'add_page_cats_and_tags' );

function my_expanded_request($q) {
    if (isset($q['tag']) || isset($q['category_name'])) {
        $q['post_type'] = array('post', 'page');
    }
    return $q;
}

add_filter('request', 'my_expanded_request');

?>


I'm using this plugin - TagPages - and it works like a charm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜