wykaz kategorii z ilością wpisów
Wykaz kategorii portalu z ilością wpisów:
<ul> <?php wp_list_categories( array( 'orderby' => 'name', 'show_count' => true, 'exclude' => array( 10 ) ) ); ?> </ul>
Wykaz kategorii i tagów do jakich należy wpis:
skrótowy:
<?php echo get_the_category_list(); ?>
rozbudowany:
<?php /* translators: used between list items, there is a space after the comma */ $categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) ); /* translators: used between list items, there is a space after the comma */ $tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) ); if ( '' != $tag_list ) { $utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } elseif ( '' != $categories_list ) { $utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } else { $utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' ); } printf( $utility_text, $categories_list, $tag_list, esc_url( get_permalink() ), the_title_attribute( 'echo=0' ), get_the_author(), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) ); ?>
–
<?php $args = array( 'posts_per_page' => 12 ); $query = new WP_Query($args); $q = array(); while ( $query->have_posts() ) { $query->the_post(); $a = '<a href="'. get_permalink() .'">' . get_the_title() .'</a>'; $categories = get_the_category(); foreach ( $categories as $key=>$category ) { $b = '<a href="' . get_category_link( $category ) . '">' . $category->name . '</a>'; } $q[$b][] = $a; // Create an array with the category names and post titles } /* Restore original Post Data */ wp_reset_postdata(); foreach ($q as $key=>$values) { echo $key; echo '<ul>'; foreach ($values as $value){ echo '<li class="post">' . $value . '</li>'; } echo '</ul>'; } ?>
wykaz postów kategorii w function.php:
// get single post for aside in single.php function get_cat_posts($q = 1, $cat = 0) { $args = array( 'post_type' => 'post', 'cat' => array($cat), 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => $q ); // The Query $query = new WP_Query( $args ); return $query; };
w kodzie strony:
<div class="last-news"> <?php $query = get_cat_posts(1,8); ?> <?php if ($query-> have_posts()) : ?> <?php while( $query->have_posts() ) : $query->the_post(); ?> <?php include(TEMPLATEPATH . '/_content-post.php'); ?> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php endif; ?> </div>
–
Wykaz wpisów kategorii z orderby menu_order
<?php $cat_posts = new WP_Query($query_string."&orderby=menu_order post_date&order=DESC"); if ($cat_posts->have_posts()): while($cat_posts->have_posts()):$cat_posts->the_post(); ?> <div class="box-wpis-porada"> <h2><?php the_title(); ?></h2> <p><a href="<?php the_permalink(); ?>"><?php echo limit_words(get_the_excerpt(), '25'); echo(' [...]'); ?></a></p> </div> <?php endwhile; endif;?> <?php } ?>
Hope this helps and happy coding :)