Support » Theme: Responsive » Restricting by Category

  • I am developing a site http://www.wheretofeed.com and I am wondering whether it is possible to filter by category on the excerpts pages. I have Reviews and I want two separate pages for take-aways and restaurants. Is there a way to filter by these categories on each page?

    Thank you for the help so far.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Emil Uzelac

    (@emiluzelac)

    Theme Review Admin

    Hi,

    First and foremost we will need a child theme, for this or any other customization of your theme. When child Theme is in place, copy blog-excerpt.php to your child theme and locate the following:

    <?php
        if ( get_query_var('paged') )
    	    $paged = get_query_var('paged');
    	elseif ( get_query_var('page') )
    	    $paged = get_query_var('page');
    	else
    		$paged = 1;
    		query_posts("post_type=post&paged=$paged");
    ?>

    and replace with:

    <?php
                if ( get_query_var('paged') )
    	            $paged = get_query_var('paged');
    	        elseif ( get_query_var('page') )
    	            $paged = get_query_var('page');
    	        else
    		        $paged = 1;
    			query_posts( array (
    			    // category name
    			    'category_name' => 'featured',
    				// number of posts
    				'posts_per_page' => 3
    				)
    			);
            ?>

    'category_name' => 'featured' will be the category, change this any way you need and 'posts_per_page' => 3 will be the number of posts.

    Thanks,
    Emil

    Wow. I think this might require me to start learning some PHP and a bit more about the whole theme-child thing.

    Thank you for your help though. It’s my fault I don’t know what I need to implement it straight away. 🙂

    That seemed to work but the category is hard-coded. I need to use the same functionality for other categories on separate pages. Is there any way I can do that?

    Thank you for your help so far. It turns out creating a child theme wasn’t so bad.

    Emil Uzelac

    (@emiluzelac)

    Theme Review Admin

    just create another page template and change the category 🙂

    Emil

    Hi. I’ve tried that but he new re-named file doesn’t show up on the template options when I create a new page. I created the second template by copying the blog-excerpt.php file and renaming it.

    Unfortunately, no joy…

    Sorry to keep pestering and thanks again for all your help. Trying to learn more about PHP and WordPress.

    I’ve managed to work out how to get a different category to display: by changing the template name at the top of the file. However, when I have no items of that particular category (for example, if I delete the last item in that category, or if there are none to begin with) it throws a 404 error.

    Is there a way to check if the returned array is empty and just have a blank screen or some explanatory text: “Review coming soon!”?

    Thanks again. Starting to read a bit more about PHP.

    Emil Uzelac

    (@emiluzelac)

    Theme Review Admin

    If category does not have any post, the 404 will come up. Take a look at this post how to “exclude” empty category.

    Emil

    Thank you. I now have more than three posts so I was hoping that there would be some way to have the blog-excerpt.php indicate that there are other posts at the bottom of the page (a bit like the search result for google, where you can see that there are n number of pages of results).

    Is this possible? The “Older Posts” and “Newer Posts”, at the bottom of the page, doesn’t really seem to do anything.

    WPyogi

    (@wpyogi)

    Forum Moderator

    Please use Responsive’s forums per Emil’s request here:

    http://wordpress.org/support/topic/please-read-before-posting-a-question?replies=1

    Sorry, I just thought as it was an existing thread that it would be OK. I promise to use the official forum in future.

    Can anyone assist. I’m at the end of my tether with the pagination issue. Older posts don’t show up, even when I click on the “Older Posts” button at the bottom. Is it possible to use the WP-Pagination plugin, in my case?

    WPyogi

    (@wpyogi)

    Forum Moderator

    Have you asked on Responsive’s forums? They are usually quite quick to respond to questions.

    I’ve tried with no success; that is to say, with no answers.

    Emil Uzelac

    (@emiluzelac)

    Theme Review Admin

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Restricting by Category’ is closed to new replies.