badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Creating a page which lists posts from a specific category.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #27147
    craig.haydon
    Participant

    Hi Guys,
    We are using the Attitude Pro theme and were wondering if its possible to setup a “page” (lets call it page-lifestyle.php) that lists only posts from a specific category?
    Essentially the page would like identical to the home page except the posts are filtered.

    Example:
    http://www.mysite.com/interiors (list posts with category “interiors”)
    http://www.mysite.com/design (list posts with category “design”)
    http://www.mysite.com/lifestyle (list posts with category “lifestyle”)

    Is this doable? If so.. how would one go about setting up?

    #27154

    Hi craig.haydon,

    We cannot provide any support on the custom file that you have created. You need to hire a developer to fix it.

    Thank you!

    #27155
    craig.haydon
    Participant

    Hi Theme Horse Support Team.
    I haven’t created a custom file, i am wanting to work within the bounds of the theme.
    Thanks

    #27156

    Hi craig.haydon,

     <?php $args = array(
    	'posts_per_page'   => 5,
    	'offset'           => 0,
    	'category'         => '',
    	'category_name'    => '',
    	'orderby'          => 'date',
    	'order'            => 'DESC',
    	'include'          => '',
    	'exclude'          => '',
    	'meta_key'         => '',
    	'meta_value'       => '',
    	'post_type'        => 'post',
    	'post_mime_type'   => '',
    	'post_parent'      => '',
    	'author'	   => '',
    	'post_status'      => 'publish',
    	'suppress_filters' => true 
    );
    $posts_array = get_posts( $args ); ?>

    You can use the above code and add the category name in 'category' => ''

    View this link https://codex.wordpress.org/Template_Tags/get_posts

    If you want to show different page with different category then you can create a template and then customize the code. Create a template and customize the code.

    First of all create a child theme and then customize the code. Otherwise your customized code will be lost while updating to new version.

    It needs lots of coding so you need to hire a developer. If you are good at coding then you can customize the code too.

    Thank you!

    #27279
    craig.haydon
    Participant

    Hi TH,
    Unfortunately the get_posts (from above) didn’t work. (or at least i wasn’t able to get to work).
    This is what i did to fix my question, and perhaps it will help other newbies like me.
    1) created a new page template. (copy page.php and rename to page-template-page-blog.php)
    2) added text (line 3) to the above new file (so its shows in WP admin). “* Template Name: Page with blog posts(cat=slug)”. You really can call it anything. The text that you enter here is what shows in WP admin (dashboard) in the page -> template (dropdown)
    3) changed description to ‘* Displays posts in page based on slug’. This isn’t really necessary… but will help to remind you later what it does 🙂
    4) modified content-extensions.php (its under library > structure) function attitude_theloop(){, so it now looks like this:

    function attitude_theloop() {
    	global $post;
    	if( is_page() ) {
    		if( is_page_template( 'page-template-blog-image-large.php' ) ) {
    			attitude_theloop_for_template_blog_image_large();
    		}
    		elseif( is_page_template( 'page-template-blog-image-medium.php' ) ) {
    			attitude_theloop_for_template_blog_image_medium();
    		}
    		elseif( is_page_template( 'page-template-blog-full-content.php' ) ) {
    			attitude_theloop_for_template_blog_full_content();
    		}
    		elseif( is_page_template( 'page-template-page-blog.php' ) ) {
    			$categ = $post->post_name;
    			query_posts( "category_name=$categ&posts_per_page=10" );
    			attitude_theloop_for_archive();
    		}
    		else {
    			attitude_theloop_for_page();
    		}
    	}
    	elseif( is_single() ) {
    		attitude_theloop_for_single();
    	}
    	elseif( is_search() ) {
    		attitude_theloop_for_search();
    	}
    	else {
    		attitude_theloop_for_archive();
    	}
    }

    5) back in wp-admin, go to the page you want to change, and change its template to ‘Page with blog posts(cat=slug)’.

    There’s probable an even easier or better way to do this, but this is what worked for me… 🙂

    Enjoy

    #27298

    Thanks for sharing with us craig.haydon

    Thank you!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.