0

i would like to make a front page with the category name and under every post of the category.The code that i have tried is:

$categories_list = get_the_category_list( esc_html__( ', ', ' ' ) );
if ( $categories_list ) {

    /* translators: 1: list of categories. */
    printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'plavou_2017' ) . '</span>', $categories_list ); // WPCS: XSS OK.
}

            /* Start the Loop */
            while ( have_posts() ) : the_post();

            $args = array(
  'exclude' => '',
    'feed' => '',
);

wp_list_categories( $args );


                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( 'template-parts/content', get_post_format() );

            endwhile;

            the_posts_navigation();

        else :

            get_template_part( 'template-parts/content', 'none' );

        endif; ?>

It works at one point, but i would prefer for having the categories print again for each category, better have the category and the post of it.Now it prints all the categories again for every post.

  • You should describe the problem you have to do it by yourself, at least what you have tried or investigated; just dumping what you want to do is out of the scope of this site. Please, see how the asking section of the Help Center. – cybmeta Sep 23 '17 at 9:40
0

First of all don't require to hesitate your self as beginner in wordpress. Second, for category listing with according posts you need to do something like below:

     <ul class="et_pb_tabs_controls clearfix tab-ul">
                            <?php 
                            dynamic_sidebar('sidebar');    
                            $cate_id=get_query_var('cat');

                            global $sitepress;

                            $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

                            $sitepress->switch_lang( $sitepress->get_default_language() );

                            $args = array(
                                'type'                     => 'post',
                                'child_of'                 => 0,
                                'parent'                   => '',
                                'orderby'                  => 'name',
                                'order'                    => 'DESC',
                                'hide_empty'               => 1,
                                'hierarchical'             => 1,
                                'exclude'                  => 1,
                                'include'                  => '',
                                'number'                   => '',
                                'taxonomy'                 => 'category',
                                'pad_counts'               => false 
                                );
                            $flag=0;        
                            $inc=0;

                            foreach (get_categories( $args ) as $category):
                               $flag=($inc==0)?0:1;   
                           if( !is_array($cate_id) && $cate_id=="")
                               $category_arr[]= $category->term_id;   

                           ?>
                           <li class="et_pb_tab_0 <?php echo ($flag==0)? 'et_pb_tab_active':'';?>"><a href="#<?php echo $category->name; ?>"><?php echo $category->name; ?></a></li>
                           <?php 
                           $inc++; 
                           endforeach; ?>
                       </ul>
<?php foreach ($category_arr as $category_id):
                            $arr=array(
                                'post_type' => 'post',
                                'order'=>"ASC",
                                'cat'=>$category_id,
                                'posts_per_page' => -1,
                                'paged' => $current_page,
                                'suppress_filters' => false
                                );
                        $wpb_all_query = new WP_Query($arr); ?>
<div class=" et_pb_row et_pb_row_1 full-width">
    <?php if ( $wpb_all_query->have_posts() ) : 
    $increment=0;
    while ( $wpb_all_query->have_posts() ) : 

        if(($increment%3)==0){
            echo '</div><div class=" et_pb_row et_pb_row_1 full-width">';
        }
        $wpb_all_query->the_post(); 

        ?>
        <div class="et_pb_column et_pb_column_1_3 et_pb_column_1">
            <div class="et_pb_posts et_pb_module et_pb_bg_layout_light  et_pb_blog_0">
                <div class="entry box">
                    <!--If no results are found-->
                    <?php $post_link=  get_permalink(); ?>
                    <?php $img_path=get_the_post_thumbnail(); ?>
                    <?php $url = wp_get_attachment_url( get_post_thumbnail_id()); ?>
                    <a href="<?php echo $post_link;?>">

                      <?php  if($url !=""){
                        ?>
                        <img src="<?php echo $url; ?>" alt="">
                        <?php } ?>
                    </a>
                    <a href="<?php echo $post_link;?>"><h1><?php the_title(); ?></h1></a>
                    <p class="box-content"><?php echo(get_the_excerpt()); ?></p>
                    <div class="profile-box"> 
                        <img src="<?php bloginfo('template_url'); ?>/img/profile-icon.png" alt="" id="" data-height-percentage="54" data-actual-width="18" data-actual-height="28">  
                        <div class="pro-name"><h4><?php echo get_the_author(); ?></h4>                                   
                            <span><?php echo get_the_date(); ?></span>
                        </div>
                    </div>
                </div><!--End if no results are found-->
            </div> <!-- .et_pb_posts -->
        </div><!-- .et_pb_column -->
        <?php 
        $increment++;
        endwhile; 
        wp_reset_postdata();
        endif; 
        ?>
</div> 
  • Thanks, do you have maybe some reference material? – Phaidonas Gialis Sep 23 '17 at 9:04
  • I add just a foreach loop withe post loop inside – Phaidonas Gialis Sep 26 '17 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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