[Resolved] Display default Blog posts filtered by Category's type

Home Forums Support [Resolved] Display default Blog posts filtered by Category's type

Home Forums Support Display default Blog posts filtered by Category's type

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #715763
    Eva

    Hi there,

    Would you please help me with the piece of code (PHP, CSS?) to filter the default Blog posts based on the Category type?

    I’m not a programmer and what I’m trying to achieve is to display the blog posts here based on Category, without a need of using WP Show Posts. I would like to keep using the default blog functions on this page, with a bit more control over the design (buttons, pagination, sidebar widget design) and then use WP Show posts on another page to create a Portfolio/Event calendar by displaying a specific post category type – with a little different layout than blog post. This page can serve as a reference – Blog vs. Events

    I believe it should be easily achievable using filters like this one, most likely $options[‘categories’] but I’m giving up on trying longer without coding knowledge 😉

    I guess it should be a filter like “if the post category is/is not ‘Podujatie’ then display blog posts” but I also might be totally wrong

    The last alternative is to use WP Show posts on both pages but I’d like to keep Blog within the default functionality

    Thanks for your help in advance,
    Jan

    #715831
    Leo
    Staff
    Customer Support
    #715944
    Eva

    Hi Leo,

    I added the following snippet with Code-snippet but with no success

    function exclude_category( $query ) {
        if ( $query->is_blog() && $query->is_main_query() ) {
            $query->set( 'Podujatie', 'podujatie' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    Any idea what else I could try? Maybe GP Elements may help?

    Thank you

    #715951
    Leo
    Staff
    Customer Support

    I’m confused. So are you trying to exclude category Podujatie from the blog page or only show category Podujatie on the blog page?

    #715986
    Eva

    My mistake. I wasn’t clear enough. I’m trying to exclude category Podujatie, slug ‘podujatie’ from the Blog page

    #716001
    Leo
    Staff
    Customer Support
    #716315
    Eva

    I ended up with the following snippet. The filter add_filter('pre_get_posts', 'excludeCat'); ruined the site speed for some reason

    function exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-7' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    Thanks for help

    #716588
    Leo
    Staff
    Customer Support

    No problem 🙂

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