Categories::rewrite_rules( array $rules, string $slug, integer $base_page_id )

Description #

Add category pages rewrite rule.

Parameters #

  • $rules
    array (Required) AnsPress rules.
  • $slug
    string (Required) Slug.
  • $base_page_id
    integer (Required) Base page ID.

Changelog #

VersionDescription
unknownunknown
4.1.6Introduced.

Source #

File: addons/categories/categories.php

	public function rewrite_rules( $rules, $slug, $base_page_id ) {
		$base_slug = get_page_uri( ap_opt( 'categories_page' ) );
		update_option( 'ap_categories_path', $base_slug, true );
		$lang_rule    = str_replace( ap_base_page_slug() . '/', '', $slug );
		$lang_rewrite = str_replace( ap_opt( 'base_page' ), '', $base_page_id );

		$cat_rules = array(
			$lang_rule . $base_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => $lang_rewrite . 'index.php?question_category=$matches[#]&paged=$matches[#]&ap_page=category',
			$lang_rule . $base_slug . '/([^/]+)/?$' => $lang_rewrite . 'index.php?question_category=$matches[#]&ap_page=category',
		);

		return $cat_rules + $rules;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment