0

For News Portals, we are using WordPress successfully. But the clients are not satisfied with the WordPress default archive. They want something different like the regular index page. So, how the Custom Archive Page can be:
Custom Archive Page Design

I think the image I attached is saying everything.

The shame part is that, I, actually din't try anything with this idea. Actually I want some idea, or links, or logic, with that I can proceed with this sort of modifications.

What I initially can say:
We can do some WP_Query() for each of the blocks, but how can we grab the date from the URL (where the URL can use any permalink) into the Query?

There would be no further pagination in the archive page, the "Load More" button will load more news of the certain category (Similar to Facebook Comment). The Lead Posts are typically echoed (in our design) using Meta Key "Featured". So, in the lead query we can query for the "featured" meta key and grab them filtering by the date of the Archive.

Then Ok, how can we proceed with this sort of idea?
Please note that, I'm a WordPress enthusiast, and is not posing my task on other's head. I'm actually trying to formulate a new idea, and seeking the path of how to proceed to be success with this sort of idea. Actually I'm NOT looking for a concrete block of code. :)

1 Answer 1

2

You can get the queried date from the query vars in the $wp_query object:

if( is_date() ){
    if( isset( $wp_query->query_vars['year'] ) ){
        echo 'queried year is ' . $wp_query->query_vars['year'];
    }
    if( isset( $wp_query->query_vars['monthnum'] ) ){
        echo 'queried month is ' . $wp_query->query_vars['monthnum'];
    }
    if( isset( $wp_query->query_vars['day'] ) ){
        echo 'queried day is ' . $wp_query->query_vars['day'];
    }
}

or just via get_query_var():

echo get_query_var( 'year' );

Does that answer your question?

EDIT

You can check if the site is using pretty permalinks by checking for the presence of the permalink structure option. In that case, you can fetch and parse the m query var instead of year / monthnum / day:

if( get_option('permalink_structure') ){
    // using pretty permalinks
} else {
    // not using pretty permalinks
    // note that month or day may be empty
    // test for their existence before trying to use!
    $year = substr( get_query_var( 'm' ), 0, 4);
    $month = substr( get_query_var( 'm' ), 4, 2);
    $day = substr( get_query_var( 'm' ), 6, 2);
}
3
  • Nice, @Milo. It's working fine with the %postname% permalink and correctly answered my Question, yes - so I marked your answer as Accepted. But is that any way we can code so that it can work with all sorts of permalinks allowed by WordPress - I think there are only two possibilities - the default one (machine readable /?m=20131121) and the others (human readable /2013/11/21). The code is not working with the Default Permalink. Nov 22, 2013 at 4:49
  • @MayeenulIslam - see edit above.
    – Milo
    Nov 22, 2013 at 16:25
  • Thanks @Milo. It's absolutely THE code. Combination of both is working perfectly - as they were expected. Nice solution. I'll implement the new Archive page ASAP inshALLAH, and let you know. Thanks again. Nov 23, 2013 at 7:02

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.