all from all categories except for one where I want only 5..
-
I’m working on a site where its all based on categories, all posts are shown on index and are filtered with jquery. Works wonders! Just that one category are normal blogposts and I dont want the content to drown in blogposts.
So my question is:
Is there a way to show only 5 blogposts from the category ‘blogg’ and all the posts from the other categories? And then when filtering on ‘blogg’ see all blogg-posts, not just 5?The code I have for now is:
$args = array( 'numberposts' => -1, 'orderby' => 'rand'); $rand_posts = get_posts( $args ); foreach ( $rand_posts as $thumbnail ) { if ( has_post_thumbnail( $thumbnail->ID ) ) { $categories = get_the_category( $thumbnail->ID ); $cat_slug = ""; if ( $categories ) { $cat_slug = $categories[0]->slug; } $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($thumbnail->ID), 'thumbnail'); $placeholder = get_bloginfo('stylesheet_directory')."/assets/placeholder.gif"; $thumb = get_the_post_thumbnail( $thumbnail->ID, 'thumbnail' ); echo '<a class="showdiv" href="' . get_permalink( $thumbnail->ID ) . '" title="'.esc_attr( $thumbnail->post_title ).'">'; echo ' <div class="'. $cat_slug. ' element">'; // echo get_the_post_thumbnail( $thumbnail->ID, 'thumbnail' ); echo "<img class='lazy' data-original='$large_image_url[0]' src='$placeholder'>"; echo "</div>"; echo "</a>"; } }
And the menu with filtering:
<?php $args=array( 'orderby' => 'term_group', 'order' => 'DESC' ); $categories=get_categories($args); echo '<ul id="filters">'; echo ' <li> <a href="'.home_url().'" title="Allt">Visa allt</a> </li> '; foreach($categories as $category) { echo ' <li> <a href="'.home_url().'">name.'" data-filter="' . $category->slug. '">' . $category->name.'</a> </li> '; } echo ''; ?>
Very very grateful for any suggestion!
- The topic ‘all from all categories except for one where I want only 5..’ is closed to new replies.