0

I am trying to add archives to a sidebar in my wordpress blog. I use: <?php wp_get_archives('cat=1'); ?> to get display the archives. I now see on the screen the past few months when I have posted content however when I click on the month to see those posts it just takes me back to the homepage instead of pulling up the posts. If someone could explain why this is happening and how to solve it that would be great.

2 Answers 2

0

are you using archives widget? if not then which function you are calling to get archives.

try to add this code (below) in your sidebar.

<?php $archives = wp_get_archives('type=monthly&limit=10&echo=0');
if ($archives) { ?>
  <ul class="archive-list">
     <?php echo $archives; ?>
  </ul>
<?php } ?>

this will output as an unordered list of last 10 monthly archives, you can change limit and type to weekly or as needed.

for more information about wp_get_archives found on codex here

13
  • I am quite confused. I just want in my sidebar on my blog page an archives for cat with id=1. When the archive is clicked it will take me to a page with the posts from cat=1 for that month. I have a sidebar php file and I registered the sidebar in my functions.
    – BDGapps
    Commented Aug 15, 2013 at 20:47
  • i think you are trying to display posts by category 1, for this wp_get_archives(); is not appropriate function because cat is not a valid pram, if this is the case then you need to use wp_query or get_posts for the category 1.
    – Anjum
    Commented Aug 15, 2013 at 21:00
  • i want to be able to get the posts from cat=1 by month
    – BDGapps
    Commented Aug 15, 2013 at 21:02
  • are you want to display months links in the sidebar and then click on month link want to display posts by this month from cat 1?
    – Anjum
    Commented Aug 15, 2013 at 21:05
  • yes sorry for the confusion.(isn't that how an archive works?)
    – BDGapps
    Commented Aug 15, 2013 at 21:06
0

This sounds like you don't have an archive.php. Without this, WP will default to index.php.

See the template hierarchy in the codex.

Maybe grab an archive.php from a standard theme (such as twentythirteen) and go from there.

5
  • i copied my page.php into my archive.php
    – BDGapps
    Commented Aug 15, 2013 at 20:55
  • That was an unusual move.
    – vancoder
    Commented Aug 15, 2013 at 20:57
  • can u please explain setting up archives
    – BDGapps
    Commented Aug 15, 2013 at 20:58
  • As I said, you can copy archive.php from a standard theme. Although, I assume you are using an off-the-shelf theme, so you should try and replace the archive.php you overwrote.
    – vancoder
    Commented Aug 15, 2013 at 21:00
  • my theme is completely custom
    – BDGapps
    Commented Aug 15, 2013 at 21:00

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.