Setup an Archive list on the right of my page and the design has a “view” button after each item.
I’m trying to have that view button link to the archive month page.
Looking at doing something with the after and adding a href=”” to the view button, However not sure what to reference to get that to happen.
My current code is as follows :
<?php
// Get Archives'
$args = array (
'type' => 'monthly',
'order' => 'DESC',
'after' => '<div class="pull-right"><a class="view" href="#">View</a></div>',
'limit' => '6'
);
$archives = wp_get_archives( $args );
?>
As you can see the ‘after’ parameter in the array is where I am trying to add the href.
Hope that makes sense.
Thank You!
Few things about
wp_get_archives
:It doesn’t return anything except if you force the
echo
parameter to0
– otherwise calling the function will result of the archive links to be printed.The
after
parameter is dependant of theformat
parameter – it is only used when using the “html” (default – list mode) or “custom” format. What it does is to display the value you pass as parameter after the link. So you don’t need to reference the link inside. Use it in combination with thebefore
parameter to achieve what you want to do here.You don’t really need to set the
type
asmonthly
, as it is the default value for this parameter. Same for theorder
parameter, which default is allreadyDESC
.So a valid call would be:
You probably notice that it doesn’t output exactly what you are trying to do, as it miss the
class
view
on your links. You need to add a filter onget_archives_link
in order to achieve this (this go in your theme functions.php):This will add the class before the
href
attribute.