Home / Forums / WoodMart support forum / Insert / cancel articles on blog Page
Home › Forums › WoodMart support forum › Insert / cancel articles on blog Page
Insert / cancel articles on blog Page
- This topic has 4 replies, 2 voices, and was last updated 2 years ago by
Aizaz Imtiaz Awan.
-
AuthorPosts
-
June 26, 2024 at 7:38 pm #575741
silvioghiaParticipantGreetings,
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!
June 27, 2024 at 12:27 pm #575896Hello,
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.
June 27, 2024 at 12:27 pm #575897Hello,
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.
June 28, 2024 at 11:03 am #576163
silvioghiaParticipantThanks 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?
June 28, 2024 at 3:10 pm #576234Hello,
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.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register