WordPress.org

Ready to get started?Download WordPress

Forums

Responsive
Restricting by Category (15 posts)

  1. TripleMoxy
    Member
    Posted 1 year ago #

    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.

  2. Emil Uzelac
    Theme Review Admin
    Posted 1 year ago #

    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

  3. TripleMoxy
    Member
    Posted 1 year ago #

    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. :)

  4. TripleMoxy
    Member
    Posted 1 year ago #

    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.

  5. Emil Uzelac
    Theme Review Admin
    Posted 1 year ago #

    just create another page template and change the category :)

    Emil

  6. TripleMoxy
    Member
    Posted 1 year ago #

    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.

  7. TripleMoxy
    Member
    Posted 1 year ago #

    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.

  8. Emil Uzelac
    Theme Review Admin
    Posted 1 year ago #

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

    Emil

  9. TripleMoxy
    Member
    Posted 1 year ago #

    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.

  10. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

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

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

  11. TripleMoxy
    Member
    Posted 1 year ago #

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

  12. TripleMoxy
    Member
    Posted 1 year ago #

    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?

  13. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

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

  14. TripleMoxy
    Member
    Posted 1 year ago #

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

  15. Emil Uzelac
    Theme Review Admin
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic