最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

widget to output a link to archive view

programmeradmin0浏览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

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

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

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

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

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

Share Improve this question edited Jun 12, 2020 at 17:10 810311 asked Jun 7, 2020 at 23:34 810311810311 417 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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
发布评论

评论列表(0)

  1. 暂无评论