I would like to solve the problem that when I press the category button on the article list screen created in archive.php of wordpress, it doesn't skip to the article list page by category.

Asked 2 years ago, Updated 2 years ago, 88 views

I create my own theme with wordpress.
I created a post list page with archive.php, but I would like to solve the problem of clicking on the category link of the article but not going to the category list.

Status

Created an article listing page with archive.php.
When you click on a category for a contributed article, all articles are displayed regardless of category (the URL shows the category).

Desired conditions

If you click on the category of new articles (e.g., "cat") displayed on the Article List page, you will want to see a list of only the articles that have the category set by cat.

Current Code

<?php get_header();?>

    <section>
      <div class="diary-h"><h2>Diary listing</h2><div>

    <?php
global$post;
$args=array('posts_per_page'=>50);
$myposts=get_posts($args);
foreach($myposts as$post){
   setup_postdata($post);
?>
<div class="diary-item">
  <div class="diary-img">
    <?php the_post_thumbnail('index_thumbnail');?>
  </div>
  <div class="diary-text">
   <div class="diary-time">
       <?php the_time('Y.m.d')?>    
   </div>
   <div class="diary-category">
       <?php the_category(', ')?>
   </div>
   <div class="diary-title">
     <a href="<?php the_permalink();?>">?php the_title();?>/a>
    </div>
  </div>
</div>
<?php
}
wp_reset_postdata();
?>

    </section>

    <?php get_footer();?>
    <?php get_sidebar();?>

php wordpress

2022-09-29 21:39

1 Answers

Create category - 〇 ..php by category and obtain each

That's how it was solved!
Thank you to everyone who viewed it!!


2022-09-29 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.