php - Sort Posts By Category? -



php - Sort Posts By Category? -

googled hours, cannot find solution.

on theme have browse page pulls videos custom post type working with. if user makes 30 categories id users able sort videos using category buttons listed @ top. if click on horror id loop show horror videos.

how can sort videos using categories within loop?

browse page

my category ul li a

<ul class="sort-by-category"> <? $args = array( 'orderby' => 'name', 'parent' => 0 ); $categories = get_categories( $args ); foreach ( $categories $category ) { echo '<li><a class="browse-categories" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a></li>'; } ?> </ul> <? // our variables $numposts = (isset($_get['numposts'])) ? $_get['numposts'] : 0; $page = (isset($_get['pagenumber'])) ? $_get['pagenumber'] : 0; query_posts(array( 'posts_per_page' => $numposts, 'paged' => $page, 'post_type' => 'theme_video' )); // our loop if (have_posts()) { while (have_posts()){ the_post(); get_template_part( 'partials/content', 'browse' ); } } wp_reset_query(); ?>

i'm bit lost on how proceed. nil tried seems sort loop, , methods ive used have been outdated 1-2 years...

site works first theme, not know how loop sort category select. tips or pointers?

thanks!

edit: reply has been found , posting else has issue. if have improve ways of accomplishing please post below benefit of others.

place code in category.php. automatically grab category url , pass cat => $category_id , update loop accordingly.

<ul class="sort-by-category"> <? $args = array( 'orderby' => 'name', 'parent' => 0 ); $categories = get_categories( $args ); foreach ( $categories $category ) { echo '<li><a class="browse-categories" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a></li>'; } ?> </ul> <? // our variables $page = (isset($_get['pagenumber'])) ? $_get['pagenumber'] : 0; // grab slug url $category_id = get_query_var('cat'); // define args $args = array( 'posts_per_page' => '36', 'paged' => $page, 'post_type' => 'theme_video', 'cat' => $category_id ); // place args in query $category_posts = new wp_query($args); // our loop if($category_posts->have_posts()) { while($category_posts->have_posts()) { $category_posts->the_post(); get_template_part( 'partials/content', 'browse' ); } } wp_reset_query(); ?>

php sorting loops category

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -