Site logo

[Resolved] Dispatch theme: Posts showing up twice on homepage

Home Forums Support [Resolved] Dispatch theme: Posts showing up twice on homepage

Home Forums Support Dispatch theme: Posts showing up twice on homepage

Viewing 12 posts - 16 through 27 (of 27 total)
  • Author
    Posts
  • #1888790
    Malin

    Hi again,
    No, got that Parse error again…
    🙂

    #1889018
    David
    Staff
    Customer Support
    #1889578
    Malin

    Hi,
    Great! Thank you, now the duplicates stopped. Well done!
    Now, the next step, is it possible to remove certain categories, like Events listings? I.e. the categories here:
    https://www.alternativephotography.com/community/events-listings/
    That would be awsome!

    #1889818
    David
    Staff
    Customer Support

    Thats great – glad we got there – i think thats going to come in very useful 🙂

    So for the main post listing you can exclude categories using this function:

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

    You need to change the xx to the ID of the Category, you can get the Category ID by editing the Category and looking in the URL it will say ID=66 or something.

    Make sure you keep the - minus. So if the ID is 66 this line will be:

    $query->set( 'cat', '-66' );

    #1892454
    Malin

    Hi David,
    Thank you for your relentless help. Two questions:

    1. Do I add this snippet after the other code you supplied, or do i do a new snippet with this code?

    2. How do I exclude more than one category, for example 66 and 67? Like this?
    $query->set( 'cat', '-66', '-67' );

    Thank you again!

    #1892689
    Elvin
    Staff
    Customer Support

    Hi there,

    for #1,

    It’s best to create a new one and write a label on it if it has a different purpose.

    For #2:

    Use array function for this.

    Example:

    $query->set( 'cat', array( '-66', '-67' ) );

    #1893032
    Malin

    Works like a dream! Thank you so much to all of you: David, Tom and Elvin for helping me out! Very much appreciated!

    #1893143
    David
    Staff
    Customer Support

    You’re welcome.
    I would like to say thank you to you, for your patience and helping us to achieve this solution 🙂

    #1893876
    Malin

    Ah, I was maybe a little too quick. Posted another post today, and it actually ended up in the list below the first 4. Any ideas?

    #1894327
    David
    Staff
    Customer Support

    Should it have appeared in the Top 4 Grid ?

    #1894334
    Malin

    Doh! Sorry, my bad! That particular post is not supposed to be in the top 4. Apologies, perhaps we can delete my comment and this one not to confuse others who may benefit from reading this thread. Thank you and sorry for the confusion.

    #1894403
    David
    Staff
    Customer Support

    No problems 🙂 Glad to hear its ok!

Viewing 12 posts - 16 through 27 (of 27 total)
  • You must be logged in to reply to this topic.