Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1313091

    Hello,

    I know that in the layout builder “blog posts” module, it is possible to select multiple categories from which posts would be only displayed on that page. However, I was wondering if there is a way of blocking a select group blog posts to show on a general blog index page? To clarify, I want to do this because i have a general “news” page that show all of the blog posts from all categories. But there is a select group of blog posts that I would only like displayed on a different page, these blog posts are in several categories that overlap with the categories i want to display in the main “news” page. So even if i were to select all the other categories other than the ones i wanted to hide on the main news page, it would carry over to hiding some that i did want to show. (hope that explanation makes sense)

    Because of this, I was hoping to find a way just to add or do something to the 4 blog posts I don’t want to display on the main “news” page that wouldn’t compromise the visibility of the other blog posts i want to show.

    Let me know if I need to clarify and explain this issue further.

    Best,

    Joe

    #1313904

    Hey jifei,

    Thank you for the inquiry.

    If you are using the Blog Posts element, then we could use the “avia_blog_post_query” to adjust the posts query in a specific page. You may need to use the post__not_in parameter to exclude specific posts.

    // https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters

    Related threads:

    // https://kriesi.at/support/topic/hide-categories-from-you-might-also-like-section-on-blog-posts/#post-1192667
    // https://kriesi.at/support/topic/do-not-allow-duplicate-posts-on-the-entire-page-not-working/#post-1291806
    // https://kriesi.at/support/topic/hide-current-blog-post-from-a-random-blog-post-slider-grid-element/

    Best regards,
    Ismael

    #1314209

    Hi Ismael,

    Thanks for the information! I’ve looked through the references you sent, but I am still having some trouble understanding where and how to implement these. Do these go into the Quick CSS or enfold Child themes folders and how is the code formatted?

    If possible, would you be able to add the code directly? I’ve included the login and pages / posts I was referring to in the private content section below.

    Best,

    Joe

    #1314982

    Hi,

    Thank you for following up.

    The connection to the site is timing out. Is it currently down?

    Hosting Server Connect Timeout
    HTTP 502 — Unable to Connect to the Origin Server
    

    Example of the code with the post__not_in parameter

    function ava_exclude_specific_posts($query) {
    	if (is_page(123)) {
    		$exclude = array(1, 3, 23, 13);
    		$query->set( 'post__not_in', $exclude );
    	}
    }
    
    add_action('pre_get_posts', 'ava_exclude_specific_posts');
    

    You need to specify the IDs of the pages that you want to exclude in this array.

    $exclude = array(1, 3, 23, 13);
    

    You will also have to adjust the value in is_page conditional function.

    Best regards,
    Ismael

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