Advertisement
Guest User

Untitled

a guest
May 31st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function wpa_alter_cat_links( $termlink, $term, $taxonomy ){
  2. if( 'category' != $taxonomy ) return $termlink;
  3.  
  4. return str_replace( '/category', '', $termlink );
  5. }
  6. add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );
  7.  
  8. function wpa_alter_cat_links( $termlink, $term, $taxonomy ){
  9. if( 'category' == $taxonomy && 0 == $term->parent ){
  10. return str_replace( '/category', '', $termlink );
  11. }
  12. return $termlink;
  13. }
  14. add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );
  15.  
  16. RedirectMatch 301 ^/category/(.*)$ /$1
  17.  
  18. function loadPageFirst() {
  19. // get the actual category
  20. $actualCategory = get_category (get_query_var('cat'));
  21. // get the page with the same slug
  22. $matchingPage = get_page_by_path($actualCategory->slug);
  23.  
  24. // If no match, load the normal listing template and exit (edit if you are using a custom listing template, eg. category.php)
  25. if (!$matchingPage) {
  26. include( get_template_directory() . '/archive.php');
  27. die();
  28. }
  29.  
  30. // Make a new query with the page's ID and load the page template
  31. query_posts('page_id='.$matchingPage->ID);
  32. include( get_template_directory() . '/page.php');
  33. }
  34.  
  35. add_filter( 'category_template', 'loadPageFirst' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement