• Hi there,

    Is it possible to get the archives list to display the month only? For example, January as opposed to January 2014.

    I’m trying to create an archives intro that is tabbed by year:

    https://www.everly.co.uk/2009/12/

    But I’m not very good with code outside out HTML and CSS and I can’t figure it out!

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    If you mean the archives widget or anything that uses wp_get_archives(), you can filter the HTML output with ‘get_archives_link’. You would need to use something like preg_replace() to remove the link text year without removing the year in the actual URL.

    The year removal would be applied to any use of wp_get_archives() or get_archives_link() anywhere in WP unless you can figure out how to distinguish the widget use (or what ever use) from other uses. One way would be add the filter just before it is needed, then remove it as soon as you are finished with it.

    Thread Starter hannahhayes

    (@hannahhayes)

    Hi bcworkz, sorry for my slow reply. That sounds like exactly what I need, but being a total rookie when it comes to this stuff I have no idea how to implement it. Could you by any chance give me a little more advice/pointers?

    Moderator bcworkz

    (@bcworkz)

    If you haven’t yet, create a child theme so your changes are not lost when your theme is updated. Figuring out Regexp notation used in preg_replace() is confusing, so I’ll just give you the filter callback function. It goes on your child theme functions.php file.

    function hh_strip_year( $link ) {
       // for dropdown list
       $link = preg_replace('!\s2[0-9]{3}\s?</option!', ' </option', $link );
       // for HTML list
       $link = preg_replace('!\s2[0-9]{3}\s?</a!', ' </a', $link );
       return $link;
    }

    Copy your theme’s sidebar template to your child theme folder and locate the call to dynamic_sidebar(). You will want to add a filter to ‘get_archives_link’ just before this. Remove it again after that. Be sure it’s in a position where it will always be executed.

    I intentionally did not give you a complete answer. I like to challenge people to learn for themselves. If you just can’t be bothered or you are completely stuck, I’ll give you the rest, but I’ll need to know what theme you’re using or have you provide a copy of the sidebar template.

    Thread Starter hannahhayes

    (@hannahhayes)

    Hello again,

    Once again sorry for my slow reply. Unfortunately I don’t have a lot of free time at the moment. I understand completely what you mean about challenging people to learn for themselves and this is something I’d really like to be able to figure out for myself one day. My problem is that instead of starting from the basics and working my way up I tend to just dive straight in to the bit I want to do which means that when it comes to stuff like this I just end up going in circles! I’ve recently signed up to something called Treehouse and I’m forcing myself to sit through the easy videos in the hope that I’ll eventually learn the harder stuff properly!

    The theme I’m using at the moment is Thesis (v 2.1), so I’m not sure if creating a child theme is necessary? I also haven’t been able to locate my sidebar template. Thesis is great for customising from the admin screen but not so great when you’re trying to access certain php files it would seem. Do you have any advice?

    Also thanks for your help so far, I really appreciate it.

    Moderator bcworkz

    (@bcworkz)

    I’m unfamiliar with Thesis so my advice based on what I know of themes in general could be seriously flawed. I was hoping it was a theme from the repository, I would then have full access to source code without you needing to figure anything out. Since it is a paid commercial theme, you shouldn’t even post their code in a public forum. I’m afraid my offer to give you a complete solution needs to be rescinded, you’re going to have to do some of this yourself.

    Any time you alter theme files, you want to create a child theme. Even if your theme has provisions for customization, such information is stored in a particular place different than the changes you are doing here. If you do not create a child theme, and instead directly alter the theme files, next time the theme updates, all your changes are lost. Using a child theme protects your changes so you never need to hesitate to apply an update. Unfortunately, some commercial themes are actually child themes, with a common parent used by several different themes. Since you cannot create grandchild themes, these themes are not good candidates for hacking.

    Determining which template file outputs a certain part of a page can be very challenging. There are a few plugins that help you identify which templates are used for any given page. I usually just add an HTML comment near the top of candidate files. When the resulting page source is viewed with syntax highlighting, the comments stand out nicely, labeling the beginning of that template’s portion of the page.

    You could also grep or full text search for template files that contain dynamic_sidebar. One of the files with that text will be the sidebar template. Some themes actually name the file ‘sidebar.php’. Once you’ve found the template and function call, do something like this:

    add_filter('get_archives_link', 'hh_strip_year');
    dynamic_sidebar('some_label');
    remove_filter('get_archives_link', 'hh_strip_year')

    The thing is, your actual code will likely not look like this, dynamic_sidebar() may be in some structure such that the first opportune place to remove the filter could be many lines down. Depending on what else is happening, the code may need to be wrapped in <?php ?> tags. You’re going to need to have some clue about basic syntax to make the right choices.

    I hope you are able to work this out, good luck!

    Thread Starter hannahhayes

    (@hannahhayes)

    Finally had some time to sit down and work on this today and I think it’s working! I skipped creating a child theme just while I was experimenting but I will definitely go back and do it now that I know I can make it work. Thank you so much for your help on this!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Removing year from archive list’ is closed to new replies.