• Hey community,

    let’s say I create a category page with the url “abc.com/xyz/” and a page with the same url “abc.com/xyz/. If I now click on the url wordpress will favor and display the category page.

    How can I change that hierarchy? If I visit “abc.com/xyz/ I want wordpress to show me the page instead of the category archive. Any solutions?

    Hope you guys can help.

Viewing 1 replies (of 1 total)
  • Thread Starter luboast

    (@luboast)

    I found the following solution, even thoug I am not exactly sure what is happening here:

    function loadPageFirst(){// get the actual category
    $actualCategory = get_category( get_query_var('cat'));
    // get the page with the same slug
    $matchingPage = get_page_by_path( $actualCategory->slug );
    
    // If no match, load the normal listing template and exit (edit if you are using a custom listing template, eg. category.php)
    if(!$matchingPage){
    include( get_template_directory().'/archive.php');
    die();
    }
    
    // Make a new query with the page's ID and load the page template
    query_posts('page_id='. $matchingPage->ID );
    include( get_template_directory().'/page.php');
    die();
    }add_filter('category_template','loadPageFirst');

    Are there any remarks on this solution?

Viewing 1 replies (of 1 total)
  • The topic ‘How to: Prioritize Page Slug over Category Slug?’ is closed to new replies.