• Resolved asquare

    (@asquare)


    Hi

    How do you retrieve the url of the archive you are looking at? Is there an equivalent to get_search_query() for archives, something like get_archive_query()? Thanks.

    Garrett

Viewing 5 replies - 1 through 5 (of 5 total)
  • Nope unfortunately not… (not that i could find)..

    What is it you’d like to retrieve? You can check the query variables to see if a month or year is queried etc…

    I’m sure we can knock something up, depending what you need it to do..

    For example to get the queried month you could do..
    <?php echo date('M',mktime(get_query_var('monthnum'))); ?>
    or for the year..
    <?php echo date('Y',mktime(get_query_var('year'))); ?>

    Thread Starter asquare

    (@asquare)

    mmm must be something with the year and month there that can be built into a url, suppose I could use $_SERVER[‘PHP_SELF’] if I’m stuck.

    I’m just putting some QR Codes on my site which will generate for each type of page so I need to pass the current url. I’m using get_permalink() for singles and get_search_query() for search pages just need to put the gap of archive pages.

    Garrett

    get_query_var('monthnum')

    Would be empty (or zero) if a query for a particular month doesn’t exist…
    So just check each one, and build your URL based on whether they exist…
    get_query_var('monthnum')
    get_query_var('day')
    get_query_var('year')

    Thread Starter asquare

    (@asquare)

    pheww that was far more complex that I had thought it would be, I completely forgot ‘archives’ were subdivided into lots of different things but I think I’ve caught them all now. Thanks for pointing me in the right direction with get_query_var that solved several issues.

    Below is the final version in case it helps anybody else, this is the function call for the super-cool-qrcode plugin (but getting those urls is relevant to lots of things) and it can be seen working here now: https://www.asquare.org/networkresearch/2009/art-by-telephone

    Garrett

    //which ype of page are we viewing?
    //render an appropriate QR Code
    switch (1)
    {
    	//for posts
    	case (is_single()):
    		echo '<img src="'.sqr_url(get_permalink(), "165", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//for pages
    	case (is_page()):
    		echo '<img src="'.sqr_url(get_permalink(), "176", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//for category archives
    	case is_category():
    		echo '<img src="'.sqr_url(get_bloginfo('url').get_option('category_base')."/".get_query_var('category_name'), "165", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//for tag archives
    	case is_tag():
    		echo '<img src="'.sqr_url(get_bloginfo('url').get_option('tag_base')."/".get_query_var('tag'), "174", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//currently not used
    	//for author archives
    	//case is_author():
    		//echo '<img src="'.sqr_url(, "165", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		//break;
    
    	//for date archives
    	case is_date():
    		echo '<img src="'.sqr_url(get_bloginfo('url')."/".get_query_var('year')."/".zeroise(get_query_var('monthnum'), 2), "174", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//for search pages
    	case is_search():
    		echo '<img src="'.sqr_url(get_bloginfo('url')."/index.php?s=".get_search_query()."&submit=", "165", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    
    	//for everything else
    	default:
    		echo '<img src="'.sqr_url(get_bloginfo('url'), "174", "UTF-8", "L", "0").'" width="175" height="175" border="0" />';
    		break;
    }

    ?? Glad you got working .. ??

    Had a brief read about QR Code, not seen it before… interesting… ?? not that i have a mobile….. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘url of the current archive’ is closed to new replies.