Modification of category template in WordPress using PHP

191

I am having some trouble building the category template i want. Here is an example of one of my categories: http://transcorrect.bg/pi-de/category/versicherungen/

I want this field http://prntscr.com/k2d5xg to show posts only from the current category. I am attaching the code i am using right now, but it is only for specific category. What i want is to be on archive.php file as a code, that takes dynamically the category ID.

Minimal example of code

  <div >
  <div >Weitere Artikel</div>
  <?php
  // get the top-category posts
  $the_query = new WP_Query(array(
    'category_name' => 'Versicherungen',
    'posts_per_page' => 10,
  ));                                   
  if ($the_query->have_posts()) : ?>
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
      <div id="list-news-home" >
        <img src="http://transcorrect.bg/pi-de/wp-content/uploads/2018/07/arrow1.png" ><a href="<?php echo get_permalink(); ?>" ><?php the_title(); ?></a>
        <a href="<?php echo get_permalink(); ?>" > [ mehr ] </a>
      </div>                                  
      <hr > 
    <?php endwhile; ?>
  <?php endif; ?>    
</div>

I can't figure out how to get it so if someone has made something similar i will be thankful to know how :)

699

Answer

Solution:

I have worked it out. If anyone needs similar thing i am posting how i converted the code i posted earlier.

<div >
 <div >Weitere Artikel</div>
  <?php $current_cat_id = get_query_var('cat'); $showposts = 10;

$args = array('cat' => $current_cat_id, 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => $showposts,'post_status' => 'publish'); query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); ?> " class="page_speed_678112518 page_speed_1044101856"> " class="page_speed_678112518 page_speed_1044101856"> [ mehr ]

        <?php endwhile; ?>
    <?php endif; ?>  

People are also looking for solutions to the problem: php - Use data attributes in laravel form select

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.