0

One of my client is developing a SmartPhone Apps with the WordPress site I've made for them. The site is of a daily newspaper's online version. All the news are sorted by different categories. So the Apps developer is taking the category feed along with an archive feed ('Archive with category' in the example here). So, in Default Permalink the feed URL is like:

http://domain/?m=YYYYMMDD&feed=rss2&cat=##

It's working fine for us.

Now for many reasons we want to switch to the %postname% permalink. In my study, I found the URL changes are like below:

FOR DEFAULT PERMALINKS

  • Category: http://domain/?cat=3
  • Archive: http://domain/?m=YYYYMMDD
  • Archive with category: http://domain/?m=YYYYMMDD&cat=##

FOR POSTNAME PERMALINKS

  • Category: http://domain/category/cat-name/
  • Archive: http://domain/YYYY/MM/DD/
  • Archive with category: [???]

Problem

So, following the trend of the URL changes, if I type the URL 'Archive with category', as:

http://domain/YYYY/MM/DD/category/cat-name/

It leads to a 404 page.


Actual Question

So the problem is:

  1. I can't figure out how to get to the 'Archive with category' in %postname% permalink?
  2. If I can get into it, then will it be same for the RSS feed URL also?

1 Answer 1

1

First of all there isn't any default way of doing this as far as I'm aware.

If you use the 'Rewrite rule inspector plugin' you'll see that there isn't any default rule that combines the category, the date and the feed as parameters.

An example date rule is

([0-9]{4})/([0-9]{1,2})/?$  index.php?year=$matches[1]&monthnum=$matches[2]

and an example category rule is

category/(.+?)/?$   index.php?category_name=$matches[1]

and an example feed rule is

feed/(feed|rdf|rss|rss2|atom)/?$    index.php?&feed=$matches[1]

What you want to do is combine these three rules and create some new rules available to wordpress.

You can do this by adding the below to your functions.php

function rewrite_rules() {
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]&feed=$matches[4]',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/feed/atom
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/feed/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]&feed=feed',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/feed/
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/category/(.+?)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&daynum=$matches[3]&category_name=$matches[4]',
        'top'
    ); // /2012/01/15/category/life-the-universe-and-everything/
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/
}
add_action( 'init', 'rewrite_rules' );

Hope that answers your question, any problems let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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