Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I have the following custom wp-query working on my site:

function custom_front_page($wp_query){
    if($wp_query->get('page_id')==get_option('page_on_front')){
        $wp_query->set('post_type','album');
        $wp_query->set('page_id',''); // empty
        // fix conditional functions
        $wp_query->is_page = false;
        $wp_query->is_front_page = true;
        $wp_query->is_archive = true;
        $wp_query->is_post_type_archive = true;
    }
}
add_action('pre_get_posts','custom_front_page');

however, altering the query in this way keeps the page link in my wp_list_pages() nav from receiving the current_page_item class (it no longer thinks it's a page at all).

How can I get around this?

PS I know I can make a separate link and apply the class conditionally, but is there a way to alter the function above, or the call to wp_list_pages()?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can use the following filter:

add_filter('wp_list_pages', 'foo_bar');
function foo_bar($html){
    //Create a regex pattern to identify the LI element with preg_match
    //Create another pattern to identify the class attr and alter it with preg_replace
    return $html;
}

As I'm not familiar with the exact elements you are working with, I can't write up a regex for you. In theory, following these steps should work for you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.