Home Forums WoodMart support forum Insert / cancel articles on blog Page

Insert / cancel articles on blog Page

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #575741

    silvioghia
    Participant

    Greetings,

    I have some problem about insert or cancel a specific article on the blog page.
    Example:
    In this page https://woodmart.xtemos.com/accessories/blog/
    I want to eliminate the first article “Exploring Atlanta’s modern homes” (https://woodmart.xtemos.com/accessories/2022/04/22/exploring-atlantas-modern-homes/).
    But…wait! I dont’ want to completely cancel the article in the section “Articles”, I just want that this article is not showed on the blog page.
    The second thing I would like to do is to insert another article that I’ve just created.

    Could you explain me how to reach this two goals?

    Thank you so much!

    #575896

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Try to Add the code below to the functions.php file in your child theme:

    function excludePostId($query) {
      $postIds = array(
        870
      );
    
      if ( $query->is_home() && $query->is_main_query() ) {
        set_query_var('post__not_in', $postIds);
      }
    }
    add_action('pre_get_posts', 'excludePostId');

    Change the 870 to the ID of the post you want to exclude.

    Best Regards.

    #575897

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Try to Add the code below to the functions.php file in your child theme:

    function excludePostId($query) {
      $postIds = array(
        870
      );
    
      if ( $query->is_home() && $query->is_main_query() ) {
        set_query_var('post__not_in', $postIds);
      }
    }
    add_action('pre_get_posts', 'excludePostId');

    Change the 870 to the ID of the post you want to exclude.

    Best Regards.

    #576163

    silvioghia
    Participant

    Thanks for the explanation,

    so it seems that when this template was created, an easy way via page builder to add or remove posts on the blog page was not designed. According to your reasoning, to insert a new post that I just created I would have to write a reverse php code, for example:

    function includeSpecificPost($query) {
    $includePostId = 870;

    if ( $query->is_home() && $query->is_main_query() ) {
    $postIn = $query->get(‘post__in’);

    if ( !is_array($postIn) ) {
    $postIn = array();
    }

    $postIn[] = $includePostId;

    $query->set(‘post__in’, $postIn);
    }
    }

    add_action(‘pre_get_posts’, ‘includeSpecificPost’);

    But there’s a problem: To EXCLUDE post 870 I used Chrome’s DevTools, selecting the post to see its ID. If I want to INCLUDE a new post, how do I know the ID of the new post I just created if it is not yet present on the blog page?

    #576234

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Navigate to Posts > All Posts. Hover over one of your post titles which you have newly created. When you hover on the post title at the bottom left corner, a URL will appear. The post ID is the number between the “post=” and “&” parameters.

    Best Regards.

Viewing 5 posts - 1 through 5 (of 5 total)