• Resolved dvsmethid

    (@dvsmethid)


    I’m using the plugin eventcalendar3 to sort my blog of events by event date. Like most people using it, I also want it to sort my categories by such (not just the event default category).

    I know from the ec3 documentation that the category url needs to be in the form:

    site.com/archives/category/categoryname?ec3_after=today

    but the only way I’ve seen people mention it is in the form of a link that is included. I think thats rather confusing for a viewer and is one too many clicks to get to the desired information. I’d like it so that when they click on a category, it always goes to the above link. My php skills arent great, but I think that I should be able to concatenate the “?ec3_after-today” to the url, btu cannot find where it is done in WordPress.

    If there’s a better way to do it, I’d love to hear that as well.

    Any help is greatly appreciated

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter dvsmethid

    (@dvsmethid)

    I should also have mentioned I’m in WP 2.3

    One way I can imagine doing this is to virtually provide an ‘ec3_after’ query by presetting it through the predefined HTTP GET variable. It won’t appear in the url, but as far as WordPress is concerned it will exist:

    $_GET['ec3_after'] = 'today';

    You’ll need to edit the blog’s root index.php (rather than your theme’s index.php) to do this. Typically the entire source for it is the following:

    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', true);
    require('./wp-blog-header.php');
    ?>

    It must be added before WordPress’ wp-blog-header.php is included, otherwise it’s processed too late to be of use.

    Couple suggestions: A good idea is to make sure $_GET[‘ec3_after’] hasn’t already been set (i.e. it’s in the url). Then you don’t override it, but rather default to your value when it doesn’t exist. To set it only on category queries, we can’t use the conditional tag is_category() to test (it’s not available until wp-blog-header.php is included). Instead, use the PHP function strpos() to verify ‘/category/’ is part of the requested url path:

    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', true);
    if( !isset($_GET['ec3_after']) && strpos($_SERVER['REQUEST_URI'], '/category/') ) {
    	$_GET['ec3_after'] = 'today';
    }
    require('./wp-blog-header.php');
    ?>
    Thread Starter dvsmethid

    (@dvsmethid)

    Wow, thank you for the great and clear explanation!

    I will try this tomorrow and let you know if it works. Thanks again!

    Thread Starter dvsmethid

    (@dvsmethid)

    this worked perfectly! thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Category Redirect’ is closed to new replies.