Community Forums › Forums › Archived Forums › General Discussion › Display Posts by Category on Page
- This topic has 4 replies, 2 voices, and was last updated 9 years, 3 months ago by Brad Dalton.
-
AuthorPosts
-
April 25, 2015 at 10:30 am #149142readytoblogdesignsMember
So! I've made it much farther than I thought I would with this and it's a bit cobbled together, I'm looking for just a nudge to get me over the finish line.
I've constructed a page template that displays the page content (yay!) and paginated posts by category (double-yay!).
What I ultimately want to do, though, becomes ridiculous when I have 20+ pages that with this method would each need a template file (and for me to specifically input the category ids). That's ridiculous, right? Is there a way to modify this so that within the edit page window my client can choose this page template and use a custom field to choose which category to display? I'm not sure if this is something glaringly obvious but I've gotten this far and now my eyeballs hurt. Any assistance would be so very appreciated!!
(Note: this page needs pagination which is why I haven't used any of the available options out there. I'd like it to be as simple as the method that involves selecting the blog template and using query_args...I'm not sure if that's possible?)
<?php
/* Template Name: Location */remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
add_action( 'genesis_loop', 'genesis_standard_loop', 5 ); // show the editor contentadd_action( 'genesis_before_loop', 'wpsites_before_blog_widget' );
function wpsites_before_blog_widget() {
if( !is_paged() ) {
genesis_widget_area( 'before-blog', array(
'before' => '<div class="before-blog widget-area">',
'after' => '</div>',
));
}
}add_action( 'genesis_loop', 'rgc_do_loop' ); // Add custom loop
function rgc_do_loop() {global $post;
// arguments, adjust as needed
$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'category__in' => array(144,225,108),
'post_status' => 'publish',
'paged' => get_query_var( 'paged' )
);/*
Overwrite $wp_query with our new query.
The only reason we're doing this is so the pagination functions work,
since they use $wp_query. If pagination wasn't an issue,
use: https://gist.github.com/3218106
*/
global $wp_query;
$wp_query = new WP_Query( $args );if ( have_posts() ) :
echo '<div class="cat-posts">';
while ( have_posts() ) : the_post();
echo '<div class="cat-listing">';
echo '<div class="entry-title"> ' . get_the_title() . ' </div>'; // show the title
echo '<div class="cat-date">';
echo the_date();
echo '</div>';
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) );
}
echo get_the_excerpt();
echo '</div>';
endwhile;echo '</div>';
do_action( 'genesis_after_endwhile' );
endif;wp_reset_query();
}genesis();
April 25, 2015 at 11:24 am #149154Brad DaltonParticipantThe code is broken as it isn't embedded using the suggested method. http://www.studiopress.community/faq/#code
April 25, 2015 at 11:33 am #149156readytoblogdesignsMemberOops - sorry!
Let's see if this works:
April 26, 2015 at 8:08 am #149186readytoblogdesignsMemberI found a working solution in case this helps anyone! 🙂
June 6, 2015 at 8:01 am #155105 -
AuthorPosts
- The topic ‘Display Posts by Category on Page’ is closed to new replies.