Advertisement
Guest User

Untitled

a guest
May 1st, 2022
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Page before Category */
  2. function loadPageFirst() {
  3. // get the actual category
  4. $actualCategory = get_category( get_query_var('cat') );
  5. // get the page with the same slug
  6. $matchingPage = get_page_by_path( $actualCategory->slug );
  7.  
  8. // If no match, load the normal listing template and exit (edit if you are using a custom listing template, eg. category.php)
  9. if (!$matchingPage) {
  10. include( get_template_directory() . '/archive.php');
  11. die();
  12. }
  13.  
  14. // Make a new query with the page's ID and load the page template
  15. query_posts( 'page_id=' . $matchingPage->ID );
  16. include( get_template_directory() . '/content-page.php');
  17. die();
  18. }
  19. add_filter( 'category_template', 'loadPageFirst' );
Advertisement
RAW Paste Data Copied
Advertisement