WordPress.org

Ready to get started?Download WordPress

Forums

sidebar Link to post monthly archives (20 posts)

  1. richards1052
    Member
    Posted 9 years ago #

    can someone help me figure out how I can create a sidebar link to my monthly archives. I don't want each of the monthly links to appear on my main pg. (my blog has existed for 3 yrs.) I'd like a single link (possibly using the "Archives" that appears above my Categories) that would take you possibly to a new pg. containing links to each month.

  2. Minna
    Member
    Posted 9 years ago #

    If you still have the default WP theme files somewhere, look at the archives.php which is a page template. You could do something like that: make a page template, write a new page called Archives (or something) and choose the page template from the drop down list (on Write Page page).

  3. richards1052
    Member
    Posted 9 years ago #

    I do have the default theme files. So are you saying that what I'd do is create a new pg. template within my current theme folder? If yes, then what code from the default theme file would I add? I clearly don't want all of it since I only want to create a pg. which has links to my monthly posts. Is there a portion of the default file that would give me that? Would you know what it is?

    And then how would I create a link in the sidebar to that new pg. with the monthly links? Specifically, could I make the word 'Archives' in my sidebar into a hyperlink which did that?

  4. Minna
    Member
    Posted 9 years ago #

    Well, for example
    <?php
    /*
    Template Name: Archives
    */
    ?>
    <?php get_header(); ?>
    <h2>Archives by month</h2>
    <ul>
    <?php wp_get_archives('type=monthly'); ?>
    </ul>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I took a peek in the theme you're using and that is the structure of the other templates (first I had told you to check what the structure is to make it the same).

    You put the code in a new php file (not named archive.php, but e.g. archives.php is good), upload the page template in the current theme folder, then write a new page, title it something you like (Archives?) and use the Page template dropdown list to choose the page template.
    You can get the path to your page when you right-click View in the list of pages and choose Copy Link Location (or something similar).

    Of course you can make the word Archives into a link, you may need to style it in the stylesheet though
    <h2><a href="path/to/page"><?php _e('Archives'); ?></a></h2>

  5. richards1052
    Member
    Posted 9 years ago #

    Thanks very much! I'll try that.

  6. stchatterbox
    Member
    Posted 9 years ago #

    well, i'm having the same problem too, and I think i'd better post it here since my question is very similar to this one.

    i finally got settle in my nav bar: and I want the following pages: home, archives etc...etc....[I'm using the kubrick theme]

    just wonder where's the archive link? if not, i have to make one, right? But how? Thanks in advance.

  7. richards1052
    Member
    Posted 9 years ago #

    OK, let me review what I've done to make sure I'm doing it right. I opened notepad & inserted Minna's code into a new file. Then I saved it, calling it archives.php encoded w. utf-8. Then I uploaded this file to my current theme folder. I then created the new pg. as suggested & linked it to the new archives template. Now I have the link location:
    http://www.richardsilverstein.com/tikun_olam/archives-monthly/

    Now as to what to do with this...I decided that in my sidebar where it says "Archives" I'd like to add the word "(monthly)" hyperlinked to the above url.

    Would I do this via the sidebar template? Where within the sidebar template would I want to look to place the url?

  8. Minna
    Member
    Posted 9 years ago #

    Well, if your sidebar.php code is more or less the same as the original which I looked at, there should currently be this:
    <h2><?php _e('Archives'); ?></h2>

    You can just add the (monthly) link after Archives:
    <h2><?php _e('Archives'); ?> <a href="/tikun_olam/archives-monthly/">(monthly)</a></h2>
    or replace (monthly) with <?php _e('(monthly)'); ?> if you want to "follow suit" (_e is used in translating the page with a language package)

  9. stchatterbox
    Member
    Posted 9 years ago #

    well, actually, i've just added a nav bar located in my Kubrick header picture.
    i won't say much about the code here, since my problem is with my link.
    for example, one link to "home" of my page is as follows:
    <li class="<?php echo $highlight; ?>">">Home

    So what about my link to archives at my header? I've tried Richard's method, but there were some errors, perhaps his case is slightly different from mine now. Thanks alot!

  10. Minna
    Member
    Posted 9 years ago #

    sorry stchatterbox, I was replying to Richard

    when I visited your site some time ago, there was much more links in the vertical navigation bar, including Archives, why did you remove it? I'm not really sure what you want to link and where (and why is it so difficult). Can't you link the archives in the same way as you've linked Gallery?

  11. stchatterbox
    Member
    Posted 9 years ago #

    :oops: sorry for the interruption. do accept my apology, minna

    i'm just wondering where is my archive link that show all old archives. thanks

  12. Minna
    Member
    Posted 9 years ago #

    @stchatterbox: you mean a page where you list months and/or categories that you can then click and see the archives? That you'd need to make yourself, in the same way I explained here.

  13. stchatterbox
    Member
    Posted 9 years ago #

    yup, minna, i've tried that, but failed again.
    I've created a new page and added the code<h2>< ?php _e('Archives'); ?></h2>
    as suggested, but when i go to the archives page, oh.....it's just a header writing
    < ?php _e('Archives'); ?>

    how can i actually do that? i simply want to make an archive page like http://www.liewcf.com/blog/archives/

  14. Minna
    Member
    Posted 9 years ago #

    You misunderstood that code bit :) Richard wanted to have the Archives word that is in the sidebar linked to a page he already had made for archives. In the same post I had explained how to make a page template for archives, which is what you need.

    As you are using the default theme, you should already have an archives.php file in your theme folder. Look in Presentation > Theme Editor and check if there's "Archives" in the list (not Archive template). If there is Archives in the list, open the page (id 19) you just created and choose Archives from the Page template dropdown list (it's below the content text area). Empty the text area and save.

  15. lcf
    Member
    Posted 9 years ago #

    @stchatterbox: I use PHP Exec plugin in the Archives Page to include WP template tags(archives).

    Here is my code if you ask:
    <h2>Read by Month</h2>
    <phpcode>
    <ul>
    <?php wp_get_archives('type=monthly& show_post_count=1'); ?>
    </ul>
    </phpcode>

    <h2>Read by Category</h2>
    All entries on LiewCF.com are categorized at the time of publishing. This is a list of the categories used at LiewCF.com, as well as an indicator to show how many entries each category holds.
    <phpcode>
    <ul>
    <?php list_cats(0, '', 'name', 'asc', '', 1, 0, 1, 1, 1, 1, 0,'','','','','') ?>
    </ul>

    Hope this helps.

  16. stchatterbox
    Member
    Posted 9 years ago #

    yup, I've got how to add an archive page already! Great!
    though the sidebar looks a bit strange in my page using minna
    's code; thus i quit this time without having a sidebar on my archives page

  17. richards1052
    Member
    Posted 9 years ago #

    Minna: Here's what I've put into my current theme sidebar template:
    <h2><?php _e('Archives'); ?> <a href="http://www.richardsilverstein.com/tikun_olam/archives-monthly/">(by month)</a></h2>

    I think something's still wrong as no link is appearing at all after the word "Archives" in the sidebar.

    But the page "Monthly Archives" IS displaying in my 'Pages' section so that serves the same purpose. BTW, is there a way to turn off display of a particular pg. but leave it inside the "Pages" admin section?

  18. Minna
    Member
    Posted 9 years ago #

    Richard, the link is in the source but commented away. Did you comment it because it was doing something bad or did you accidentally put the link in the commented bit of your code?

    By "turning off display" do you mean you'd like to hide the link from the pages' link list or put page in a "draft" status like with posts? Pages don't yet have a possibility to be left as drafts but I think it's being added... But, you can exclude certain pages from the link list (where that "Monthly archives" currently is). That you do by adding exclude=x in the wp_list_pages tag (see the Codex for code examples.

    @stchatterbox: You don't need any of the code examples I gave in the sidebar... that advice didn't apply to your problem. I'm glad the archives page works now.

  19. richards1052
    Member
    Posted 9 years ago #

    Now, I'm really confused. What does "commented away" mean? I thought what I'd done is merely copy the code in your earlier post. There shouldn't be any changes in what I posted earlier today & what you suggested that I use in yr. post fr. June 18th. If there is it's inadvertent.

    If you meant by "commented away" why did I quote the entire link path rather than the abbreviated version that you used...I did this because the "by month" link never displayed next to "Archives" when I used your version of the link. So I thought maybe I should try the full path.

    How do I remove fr. the code whatever is "commenting away" the link?

    I meant I'd like to hide the link once I get your solution implemented. I don't want 2 links to monthly archives in my sidebar. I don't understand why they don't have a visible/invisible option for page display as they have for individual links display. That'd be easier then adding code.

  20. Minna
    Member
    Posted 9 years ago #

    Well, I mean that when I looked at your page and opened the source code, there was this:
    <!-- <li>
    <h2>Archives <a href="/tikun_olam/archives-monthly/">(monthly)</a></h2>
    <ul>
    </ul>
    </li> -->

    close above <h2>Archives</h2> (in the sidebar). So the "Archives (monthly)" doesn't show up in the page because it's wrapped in <!-- --> which are HTML comments, only the "Archives" will...

    And after you get the link showing you should add that exclude parametre. If you don't like that, why not make a Link category for the pages and put the links there instead, then you can control them like all links.

Topic Closed

This topic has been closed to new replies.

About this Topic