0

REVISED POST

I am trying to go a different route as the suggested answer to this post didn't work for me.

I am using child theme where I added nav widget with custom menu 'archive' containing only one page 'archives'. I used <?php dynamic_sidebar( 'sidebar-2' ); ?> in my index.php and it links to archive.php view which I was kind of trying to achieve to output my posts in yearly format

enter image description here

PROBLEM: Child theme still adds this 'archives' page to Primary menu even though I have 'Automatically add new top-level pages to this menu' unchecked. I checked parent theme functions.php but didn't find any function that can be the reason for that. I know this is the default WP behaviour.How can I stop automatically adding pages in my child theme?

BELOW IS THE OLD POST

get_archives_link first parameter description is "$url (string) (Required) URL to archive." does it mean it has to be URL to the actual archive page? can it be used to output a link to archive view (archive.php) from single.php?

below is a screenshot of the post footer from my single.php to illustrate how I am looking to output a link to archive view handled by archive.php

enter image description here

following is the code in my single.php post footer section

<footer>

<div class="dt"><?php echo get_the_date();?></div>

<div class="cat">
<?php the_category(', ');?>
</div>

<div class="tag">
  <?php the_tags();?>

</div>

<div class="arc">
<a href="<?php echo get_post_type_archive_link( 'post' ); ?>">Archives</a>
</div>

I've done extensive search on Codex but was not able to find a tag that can link to archive.php

1 Answer 1

0

get_archive_link() is used to generate internal html links for output. If you want to link to archive page from single.php why dont you use get_post_type_archive_link

here is an example of how you can use this. it takes only one parameter (post type)

<a href="<?php echo get_post_type_archive_link( 'movies' ); ?>">Movies Archive</a>
//here movies is the post type
2
  • I alredy tried what you suggest it takes me to my blog page which is handled by index.php and I need a link to archive.php view (I don't have an archive page - just archive.php)
    – 810311
    Jun 8, 2020 at 2:08
  • I tried <?php echo get_post_type_archive_link( 'post' ); ?> it takes me to index.php
    – 810311
    Jun 8, 2020 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.