• Hi!

    I’m searching to develop a slider in the home of a custom theme, which shows the subcategories of parent cat.(ex. Articles) with their featured image.(In the link see the slider under the title “In Piemonte Puoi”, is only static html with a framework, I’m working on wordpress on localhost)

    I tried to show posts from a test category, slider, changing the links in the preview, but I didn’t have success.

    Here is the code of the loop for the slider showing the posts from the category slider

                        
    <?php
    
    // La Query
    $ipp_the_query = new WP_Query( 'category_name=slider&posts_per_page=6' );
    
    // Il Loop
    while ( $ipp_the_query->have_posts() ) :
       $ipp_the_query->the_post(); ?>
    
       <?php $ipp_image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'ipp_small' ); ?>
    
       <li class="uk-padding-large">
           <a href="<?php the_permalink(); ?>">
               <img src="<?php echo $ipp_image_attributes[0]; ?>" alt="" uk-svg>
           </a>
           <div class="uk-position-center uk-panel">
    
               <div><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    
           </div>
    
       </li>
    
       <?php endwhile;
       // Ripristina Query & Post Data originali
       wp_reset_query();
       wp_reset_postdata(); ?>
    

    I would find a method to loop the subcategories(with their featured images) of a parent like the posts of the category slider in the code.

    Another solution may be change the link of the content preview(cat. slider) to the subcategories.

    Thanks for the help!
    Carlo

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    So you want the slider to display posts assigned terms that are children of “slider” instead of posts assigned the “slider” term? You need an array of child term IDs, which are passed as the “category__in” argument to WP_Query. You’ll need to change the WP_Query argument style from the current string form to the preferred array form.

    You can get child term IDs with get_categories(). Pass a “fields” argument to limit the returned data to only IDs. Pass the ID of the “slider” term as the value for arguments “parent” or “child_of”, depending on if you want immediate children or all descendants, respectively.

    Because the loop is for posts, linking to the sub-category of the post can be a bit problematic if the post has more than one category term assigned. If the sub-category is an immediate child of “slider”, its “parent” property will be the ID of the “slider” term.

Viewing 1 replies (of 1 total)
  • The topic ‘I need a slider with subcategories showed’ is closed to new replies.