Official male search item php i. Create a Custom Post Type with Custom Taxonomy

Main goals:

  • implement search in such a way that after entering a search query into a string, search results appear below this string
  • the request to get the result should occur only after the end of the search query

Okay, let's go!

An approximate layout of the block itself with the search string and div-nickname, where we will add search results:

Because search is available in the header of the site, let's add the appropriate search scripts and style the results:

// chop up the search: $ APPLICATION-\u003e AddHeadScript ("/ search / ajax_search.js"); $ APPLICATION-\u003e AddHeadScript ("/ search / jquery.mCustomScrollbar.js"); $ APPLICATION-\u003e SetAdditionalCSS (SITE_TEMPLATE_PATH. "/Css/ajax_search.css"); $ APPLICATION-\u003e SetAdditionalCSS (SITE_TEMPLATE_PATH. "/Css/jquery.mCustomScrollbar.min.css");

Now let's see what lies in our ajax_search.js:

Function get_result () (// clear the search results $ ("# search_result"). Html (""); // have not received the search results yet - display the preloader $ ("# search_result"). Append ("

"); $ .ajax ((type:" POST ", url:" /search/ajax_search.php ", data:" q \u003d "+ q, dataType:" json ", success: function (json) (// clear preloader $ ("# search_result"). html (""); $ ("# search_result"). append (" "); // add each element of the json array inside the div-nickname with class \u003d" live-search "(you can use your own layout) $ .each (json, function (index, element) ($ (" # search_result "). find (".live-search"). append (" "+ element.TITLE +""+ element.BODY_FORMATED +""); //console.log (element.BODY_FORMATED);)); // style the scrolling $ (". live-search "). mCustomScrollbar ((scrollInertia: 500));)));) var timer \u003d 0; var q \u003d ""; $ (document) .ready (function () ($ ("# q"). keyup (function () (q \u003d this.value; clearTimeout (timer); timer \u003d setTimeout (get_result, 1000) ;)); $ ("# reset_live_search"). click (function () ($ ("# search_result"). html ("");));));

keyup function we call the get_result () function, which actually fills the div-nickname with id \u003d "search_result" by ajax.

mCustomScrollbar is just a styling call (you can disable it).

We receive data from /search/ajax_search.php in JSON format.

Everything is clear with the JS component, now let's see what happens in ajax_search.php:

Search (array ("QUERY" \u003d\u003e $ q, "SITE_ID" \u003d\u003e LANG, "MODULE_ID" \u003d\u003e "iblock", "CHECK_DATES" \u003d\u003e "Y", "PARAM2" \u003d\u003e "8")); $ result \u003d array (); while ($ res \u003d $ obSearch-\u003e GetNext ()) ($ id \u003d $ res ["ITEM_ID"]; // if the section is found: if (strripos ($ id, "S")! \u003d\u003d false) ($ result_item ["TITLE"] \u003d $ res ["TITLE"]; $ result_item ["URL"] \u003d $ res ["URL"]; $ result_item ["BODY_FORMATED"] \u003d $ res ["TITLE_FORMATED"]; $ result \u003d $ result_item;) // if there is no S-ki, then else ($ result_item ["TITLE"] \u003d $ res ["TITLE"]; $ result_item ["URL"] \u003d $ res ["URL"]; $ result_item [" BODY_FORMATED "] \u003d $ res [" BODY_FORMATED "]; $ result \u003d $ result_item;)) echo json_encode ($ result); )?\u003e

In this case, the search is performed by the Search method of the Bitrix class CSearch. In PARAM2 we write in which infoblock we are looking for. We push the search results into the $ result array. Note that $ res [‘ITEM_ID’] can contain both an element and a section. Depending on what you found, in $ result_item [‘BODY_FORMATED’] we push either the section name or a piece of text from the found infoblock element.

The best way to keep a user on a site is to let them find what they are looking for. If you make a convenient system for this, then the level of preference for your site will grow and the user will definitely return in order to find what interests him.

I will show you how to create a simple, yet functionally effective, search form that will be used to search for articles on the site. The results will appear on the page without any reloads, which is undoubtedly the best way to present information.

I will create 2 files: search.php which will contain HTML and JavaScript. The second file, do_search.php, will contain the PHP code. Let's start creating the first file:

PHP, jQuery search demo

Try typing the word ajax


Results for

In this file, we have created a regular HTML form that sends a POST request to the back end file do_search.php.

select_list ($ sql); if (count ($ row)) ($ end_result \u003d ""; foreach ($ row as $ r) ($ result \u003d $ r ["title"]; $ bold \u003d " ". $ word.""; $ end_result. \u003d"

  • ". str_ireplace ($ word, $ bold, $ result)."
  • ";) echo $ end_result;) else (echo"
  • No results were found for your search.
  • "; } } ?>

    PHP code contains comments by which you can easily understand how the script works. If there are matches in the database, you show them to your user, highlighting in bold the words that the user was looking for.

    Let's give it all some CSS:

    Body (font-family: Arial, Helvetica, sans-serif;) * (margin: 0; padding: 0;) #container (margin: 0 auto; width: 600px;) a (color: # DF3D82; text-decoration: none) a: hover (color: # DF3D82; text-decoration: underline;) ul.update (list-style: none; font-size: 1.1em; margin-top: 10px) ul.update li (height: 30px; border-bottom: #dedede solid 1px; text-align: left;) ul.update li: first-child (border-top: #dedede solid 1px; height: 30px; text-align: left;) #flash (margin- top: 20px; text-align: left;) #searchresults (text-align: left; margin-top: 20px; display: none; font-family: Arial, Helvetica, sans-serif; font-size: 16px; color: # 000;) .word (font-weight: bold; color: # 000000;) #search_box (padding: 4px; border: solid 1px # 666666; width: 300px; height: 30px; font-size: 18px; -moz- border-radius: 6px; -webkit-border-radius: 6px;) .search_button (border: # 000000 solid 1px; padding: 6px; color: # 000; font-weight: bold; font-size: 16px; -moz- border-radius: 6px; -webkit-border-radius: 6px;) .found (font-weight: bold ; font-style: italic; color: # ff0000; ) h2 (margin-right: 70px;)

    Now you have learned how to create a simple search form that works without reloading the page. I hope you enjoyed the tutorial.

    template

    The name of the template by which to display site search results. Ignored in XSLT templating.

    Search_string

    Search phrase. If the value is not specified, it is taken from the request sent through the search form.

    Search_types

    List of identifiers of hierarchical types for search (separated by spaces). If no value is specified, the search is performed across all types.

    Search_branches

    The list of sections in which the search will be carried out (indicated by a space). If no value is specified, all sections are searched. The parameter can accept both page id and their URL.

    Per_page

    The number of results per page. If the parameter is not specified, the value specified in the "Search" module settings will be taken.

    % total%

    Displays the total number of news in the feed. Can be used for a macro % system numpages ()%.

    % per_page%

    Prints the value of the per_page parameter. Can be used for a macro % system numpages ()%.

    % list-class-first%

    in case the element is the first, outputs "first"

    % list-class-last%

    in case the element is the last, outputs "last"

    % list-class-odd%

    in case the element is even, outputs "odd"

    % list-class-even%

    in case the element is odd, outputs "even"

    % list-position%

    inserts a sequence number in the list

    search_empty_result

    It is used when no pages were found in the search result. In this case, this block is displayed instead of the block search_block .

    % last_search_string%

    Displays the previous search term, if any.

    search_block_line_quant

    Displays a delimiter that is inserted between search results.

    Examples of using

    Found% total% of pages.

    % lines%

    % system numpages (% total%,% per_page%)%

    END; $ FORMS ["search_block_line"] \u003d<< % num%. % name% % context%

    END; $ FORMS ["search_empty_result"] \u003d<<Excuse me. No results were found for this request.

    END; ?\u003e

    By Ibrahim Diallo

    Published Jul 2 2014 ~ 16 minutes read

    Search is an important feature on a website. When my few readers want to look for a particular passage on my blog, they use the search box. It used to be powered by Google Search, but I have since then changed it to my own home-brewed version not because I can do better but because it was an interesting challenge.

    If you are in a hurry and just want your site to be searchable, well do what I did before, use Google.

    // In search.php file $ term \u003d isset ($ _ GET ["query"])? $ _ GET ["query"]: ""; $ term \u003d urlencode ($ term); $ website \u003d urlencode ("www.yourwebsite.com"); $ redirect \u003d "https://www.google.com/search?q\u003dsite%3A($website)+($term)"; header ("Location: $ redirect"); exit;

    What it does is pretty simple. Get the term passed by the user, and forward it to Google search page. Limit the search result to our current domain using the site: keyword in the search query. All your pages that are indexed by Google will be available through search now. If you do want to handle your search in house however, then keep reading.

    Homemade Search Solution

    Before we go any further, try using the search box on this blog. It uses the same process that I will describe below. If you feel that this is what you want then please continue reading.

    This solution is catered to small websites. I make use of LIKE with wild cards on both ends, meaning your search cannot be indexed. This means the solution will work fine for your blog or personal website that doesn "t contain tons of data. Port it to a bigger website and it might become very slow. MySQL offers Full Text Search which is not what we are doing here.

    Note: If you have 5000 blog posts you are still fine. ...

    We will take the structure of this blog as a reference. Each blog post has:

    • A title p_title
    • A url p_url
    • A summary p_summary
    • A post content p_content
    • And catergories category.tagname

    For every field that matches with our search term, we will give it a score. The score will be based on the importance of the match:

    // the exact term matches is found in the title $ scoreFullTitle \u003d 6; // match the title in part $ scoreTitleKeyword \u003d 5; // the exact term matches is found in the summary $ scoreFullSummary \u003d 5; // match the summary in part $ scoreSummaryKeyword \u003d 4; // the exact term matches is found in the content $ scoreFullDocument \u003d 4; // match the document in part $ scoreDocumentKeyword \u003d 3; // matches a category $ scoreCategoryKeyword \u003d 2; // matches the url $ scoreUrlKeyword \u003d 1;

    Before we get started, there are a few words that do not contribute much to a search that should be removed. Example "in", "it", "a", "the", "of" .... We will filter those out and feel free to add any word you think is irrelevant. Another thing is, we want to limit the length of our query. We don "t want a user to write a novel in the search field and crash our MySQL server.

    // Remove unnecessary words from the search term and return them as an array function filterSearchKeys ($ query) ($ query \u003d trim (preg_replace ("/ (\\ s +) + /", "", $ query)); $ words \u003d array (); // expand this list with your words. $ list \u003d array ("in", "it", "a", "the", "of", "or", "I", "you", "he", "me", "us", "they", "she", "to", "but", "that", "this", "those", "then"); $ c \u003d 0; foreach (explode ("", $ query) as $ key) (if (in_array ($ key, $ list)) (continue;) $ words \u003d $ key; if ($ c\u003e \u003d 15) (break;) $ c ++ ;) return $ words;) // limit words number of characters function limitChars ($ query, $ limit \u003d 200) (return substr ($ query, 0, $ limit);)

    Our helper functions can now limit character count and filter useless words. The way we will implement our algorithm is by giving a score every time we find a match. We will match words using the if statement and accumulate points as we match more words. At the end we can use that score to sort our results

    Note: I will not be showing how to connect to MySQL database. If you are having problems to efficiently connect to the database I recommend reading this.

    Let "s give our function a structure first. Note I left placeholders so we can implement sections separately.

    Function search ($ query) ($ query \u003d trim ($ query); if (mb_strlen ($ query) \u003d\u003d\u003d 0) (// no need for empty search right? Return false;) $ query \u003d limitChars ($ query) ; // Weighing scores $ scoreFullTitle \u003d 6; $ scoreTitleKeyword \u003d 5; $ scoreFullSummary \u003d 5; $ scoreSummaryKeyword \u003d 4; $ scoreFullDocument \u003d 4; $ scoreDocumentKeyword \u003d 3; $ scoreCategoryKeyword \u003d 2; $ scoreUrlKeyword \u003d 1; $ keywords \u003d filterSear $ query); $ escQuery \u003d DB :: escape ($ query); // see note above to get db object $ titleSQL \u003d array (); $ sumSQL \u003d array (); $ docSQL \u003d array (); $ categorySQL \u003d array (); $ urlSQL \u003d array (); / ** Matching full occurrences PLACE HOLDER ** / / ** Matching Keywords PLACE HOLDER ** / $ sql \u003d "SELECT p.p_id, p.p_title, p.p_date_published, p. p_url, p.p_summary, p.p_content, p.thumbnail, ((- Title score ".implode (" + ", $ titleSQL).") + (- Summary ".implode (" + ", $ sumSQL) . ") + (- document" .implode ("+", $ docSQL). ") + (- tag / category" .implode ("+", $ categorySQL). ") + (- url". implode (" + ", $ urlSQL).")) as relevance FROM post p WHERE p.status \u003d "published" HAVING relevance\u003e

    In the query, all scores will be summed up as the relevance variable and we can use it to sort the results.

    Matching full occurrences

    We make sure we have some keywords first then add our query.

    If (count ($ keywords)\u003e 1) ($ titleSQL \u003d "if (p_title LIKE"% ". $ EscQuery."% ", ($ ScoreFullTitle), 0)"; $ sumSQL \u003d "if (p_summary LIKE"% " . $ escQuery. "%", ($ scoreFullSummary), 0) "; $ docSQL \u003d" if (p_content LIKE "%". $ escQuery. "%", ($ scoreFullDocument), 0) ";)

    Those are the matches with higher score. If the search term matches an article that contains these, they will have higher chances of appearing on top.

    Matching keywords occurrences

    We loop through all keywords and check if they match any of the fields. For the category match, I used a sub-query since a post can have multiple categories.

    Foreach ($ keywords as $ key) ($ titleSQL \u003d "if (p_title LIKE"% ". DB :: escape ($ key)."% ", ($ ScoreTitleKeyword), 0)"; $ sumSQL \u003d "if (p_summary LIKE "%". DB :: escape ($ key). "%", ($ ScoreSummaryKeyword), 0) "; $ docSQL \u003d" if (p_content LIKE "%". DB :: escape ($ key). "% ", ($ scoreDocumentKeyword), 0)"; $ urlSQL \u003d "if (p_url LIKE"% ". DB :: escape ($ key)."% ", ($ scoreUrlKeyword), 0)"; $ categorySQL \u003d "if ((SELECT count (category.tag_id) FROM category JOIN post_category ON post_category.tag_id \u003d category.tag_id WHERE post_category.post_id \u003d p.post_id AND category.name \u003d "" .DB :: escape ($ key). "")\u003e 0, ($ scoreCategoryKeyword), 0) ";)

    Also as pointed by a commenter below, we have to make sure that the these variables are not empty arrays or the query will fail.

    // Just incase it "s empty, add 0 if (empty ($ titleSQL)) ($ titleSQL \u003d 0;) if (empty ($ sumSQL)) ($ sumSQL \u003d 0;) if (empty ($ docSQL)) ( $ docSQL \u003d 0;) if (empty ($ urlSQL)) ($ urlSQL \u003d 0;) if (empty ($ tagSQL)) ($ tagSQL \u003d 0;)

    At the end the queries are all concatenated and added together to determine the relevance of the post to the search term.

    // Remove unnecessary words from the search term and return them as an array function filterSearchKeys ($ query) ($ query \u003d trim (preg_replace ("/ (\\ s +) + /", "", $ query)); $ words \u003d array (); // expand this list with your words. $ list \u003d array ("in", "it", "a", "the", "of", "or", "I", "you", "he", "me", "us", "they", "she", "to", "but", "that", "this", "those", "then"); $ c \u003d 0; foreach (explode ("", $ query) as $ key) (if (in_array ($ key, $ list)) (continue;) $ words \u003d $ key; if ($ c\u003e \u003d 15) (break;) $ c ++ ;) return $ words;) // limit words number of characters function limitChars ($ query, $ limit \u003d 200) (return substr ($ query, 0, $ limit);) function search ($ query) ($ query \u003d trim ($ query); if (mb_strlen ($ query) \u003d\u003d\u003d 0) (// no need for empty search right? return false;) $ query \u003d limitChars ($ query); // Weighing scores $ scoreFullTitle \u003d 6; $ scoreTitleKeyword \u003d 5; $ scoreFullSummary \u003d 5; $ scoreSummaryKeyword \u003d 4; $ scoreFullDocument \u003d 4; $ scoreDocumentKeyword \u003d 3; $ scoreCategoryKeyword \u003d 2; $ scoreUrlKe yword \u003d 1; $ keywords \u003d filterSearchKeys ($ query); $ escQuery \u003d DB :: escape ($ query); // see note above to get db object $ titleSQL \u003d array (); $ sumSQL \u003d array (); $ docSQL \u003d array (); $ categorySQL \u003d array (); $ urlSQL \u003d array (); / ** Matching full occurences ** / if (count ($ keywords)\u003e 1) ($ titleSQL \u003d "if (p_title LIKE"% ". $ EscQuery."% ", ($ ScoreFullTitle), 0)"; $ sumSQL \u003d "if (p_summary LIKE"% ". $ escQuery."% ", ($ scoreFullSummary), 0)"; $ docSQL \u003d "if (p_content LIKE"% ". $ escQuery."% ", ($ scoreFullDocument), 0) ";) / ** Matching Keywords ** / foreach ($ keywords as $ key) ($ titleSQL \u003d" if (p_title LIKE "%". DB :: escape ($ key). "%", ($ ScoreTitleKeyword ), 0) "; $ sumSQL \u003d" if (p_summary LIKE "%". DB :: escape ($ key). "%", ($ ScoreSummaryKeyword), 0) "; $ docSQL \u003d" if (p_content LIKE "% ".DB :: escape ($ key)."% ", ($ ScoreDocumentKeyword), 0)"; $ urlSQL \u003d "if (p_url LIKE"% ". DB :: escape ($ key)."% ", ( $ scoreUrlKeyword), 0) "; $ categorySQL \u003d" if ((SELECT count (category.tag_id) FROM category JOIN post_category ON post_category.tag_id \u003d category.tag_id WHERE post_category.post_id \u003d p.post_id AND category.name \u003d "". DB :: escape ($ key). "")\u003e 0, ($ scoreCategoryKeyword), 0) ";) // Just incase it" s empty, add 0 if (empty ($ titleSQL)) ($ titleSQL \u003d 0; ) if (empty ($ sumSQL)) ($ sumSQL \u003d 0; ) if (empty ($ docSQL)) ($ docSQL \u003d 0;) if (empty ($ urlSQL)) ($ urlSQL \u003d 0;) if (empty ($ tagSQL)) ($ tagSQL \u003d 0;) $ sql \u003d " SELECT p.p_id, p.p_title, p.p_date_published, p.p_url, p.p_summary, p.p_content, p.thumbnail, ((- Title score ".implode (" + ", $ titleSQL). ") + (- Summary" .implode ("+", $ sumSQL). ") + (- document" .implode ("+", $ docSQL). ") + (- tag / category" .implode ("+", $ categorySQL). ") + (- url" .implode ("+", $ urlSQL). ")) as relevance FROM post p WHERE p.status \u003d" published "HAVING relevance\u003e 0 ORDER BY relevance DESC, p.page_views DESC LIMIT 25 "; $ results \u003d DB :: query ($ sql); if (! $ results) (return false;) return $ results; )

    Now your search.php file can look like this:

    $ term \u003d isset ($ _ GET ["query"])? $ _ GET ["query"]: ""; $ search_results \u003d search ($ term); if (! $ search_results) (echo "No results"; exit;) // Print page with results here.

    We created a simple search algorithm that can handle a fair amount of content. I arbitrarily chose the score for each match, feel free to tweak it to something that works best for you. And there is always room for improvement.

    It is a good idea to track the search term coming from your users, this way you can see if most users search for the same thing. If there is a pattern, then you can save them a trip and just cache the results using Memcached.

    If you want to see this search algorithm in action, go ahead and try looking for an article on the search box on top of the page. I have added extra features like returning the part where the match was found in the text. Feel free to add features to yours.

    Did you like this article? You can subscribe to read more awesome ones. ...

    On a related note, here are some interesting articles.

    If there is one thing a web server does everyday it iss connecting to the database. I have been using PHP for many years now, but if you ask me to write a script to fetch data from the database I couldn "t do it without going back to the Ultimate PHP manual to find a few examples first.

    A few months ago I updated my PHP version. PHP 5.4 to 5.5. I never had any problems updating PHP before. I follow its development closely and try to remove my deprecated functions long before they are officially removed. But this time I was caught off guard. It silently broke part of my website for the silliest reason.

    Comments (45)

    Zaryel Aug 12 2015:

    Ian Mustafa Sep 26 2015:

    Rob Sep 29 2015:

    adeem Feb 11 2016:

    Ivan Venediktov Apr 9 2016.

    Create a custom post type Articles with custom categories (Custom Taxonomy) Articles Category.

    In my case, all standard records are Products, so we will display Articles through custom records.

    In the functions.php file, register the Articles custom post type:

    Function wptp_create_post_type () ($ labels \u003d array ("name" \u003d\u003e __ ("Articles"), "singular_name" \u003d\u003e __ ("Articles"), "add_new" \u003d\u003e __ ("New Article"), "add_new_item" \u003d\u003e __ ("Add New Article"), "edit_item" \u003d\u003e __ ("Edit Article"), "new_item" \u003d\u003e __ ("New Article"), "view_item" \u003d\u003e __ ("View Article"), "search_items" \u003d\u003e __ ("Search Articles"), "not_found" \u003d\u003e __ ("No Articles Found"), "not_found_in_trash" \u003d\u003e __ ("No Articles found in Trash"),); $ args \u003d array ( "labels" \u003d\u003e $ labels, "has_archive" \u003d\u003e true, "public" \u003d\u003e true, "hierarchical" \u003d\u003e false, "menu_position" \u003d\u003e 5, "supports" \u003d\u003e array ("title", "editor" , "excerpt", "custom-fields", "thumbnail"),); register_post_type ("articles", $ args);) add_action ("init", "wptp_create_post_type");

    If you want custom posts to display standard categories, then link them to the Category taxonomy:

    "taxonomies" \u003d\u003e array ("category"),

    If you also create custom taxonomies for custom posts, then you need to link them to the created taxonomies, if you take the example below, these will be articles_category

    "taxonomies" \u003d\u003e array ("articles_category"),

    Then, for the Articles custom post type, we register the ‘Article Category’ taxonomies so that different posts can belong to different categories.

    Function wptp_register_taxonomy () (register_taxonomy ("articles_category", "articles", array ("labels" \u003d\u003e array ("name" \u003d\u003e "Article Categories", "singular_name" \u003d\u003e "Article Category", "search_items" \u003d\u003e " Search Article Categories "," all_items "\u003d\u003e" All Article Categories "," edit_item "\u003d\u003e" Edit Article Categories "," update_item "\u003d\u003e" Update Article Category "," add_new_item "\u003d\u003e" Add New Article Category ", "new_item_name" \u003d\u003e "New Article Category Name", "menu_name" \u003d\u003e "Article Category",), "hierarchical" \u003d\u003e true, "sort" \u003d\u003e true, "args" \u003d\u003e array ("orderby" \u003d\u003e "term_order"), "show_admin_column" \u003d\u003e true));) add_action ("init", "wptp_register_taxonomy");

    For a custom taxonomy, you can change the slug to a more beautiful one so that it is not articles_category, but you need to take into account that such slugs are no longer on other pages or posts, otherwise there will be problems:

    "rewrite" \u003d\u003e array ("slug" \u003d\u003e "blog"),

    When changing slugs, you need to update the Permalink settings in the admin panel, otherwise you will receive a 404 error instead of the desired page.

    More examples can be found and. But I helped to put all this code in order, for which the author is very grateful.

    The single.php file is responsible for the appearance of a custom post, but to change the appearance of a custom post, you can create a single- (post_type) .php file - in my case, it will be single-articles.php with its content.

    Now we need to display custom posts on the page. By default, the index.php file is responsible for displaying the archive of custom posts. But you can create a file that will be responsible for displaying custom posts in your taxonomy.

    Option 1 is the most correct one. We display entries in the taxonomy in the same way as in the normal category.

    To do this, create a file taxonomy- (taxonomy) .php - in my case it will be taxonomy-articles_category.php and display a regular cycle in it, as for standard posts in a category:

    In the tax-item.php file, we display the data that we need to get from each post, for example, the title, post link, thumbnail, and excerpt.

    In the pagination.php file, we display pagination in this format.

    The cycle is not changeable, pagination works fine. This is the best option for displaying Custom Taxonomies.

    Option 2 - if there are no custom taxonomies, then you can simply get all custom entries in the form of an Archive

    To do this, create a file archive- (post_type) .php in the template - in my case it will be archive-articles.php, in which, just like in the taxonomy, we display a regular cycle, only instead of the Taxonomy header we display the name of the custom post type :

    With this option, if the archive page for a custom post has not been created, then you can get a list of all custom posts by following the direct link BLOG_URL? Post_type \u003d (post_type) or, in my case, http://site.com/articles/.

    Option 3. Just display all custom Articles posts on a page with a given template

    "articles", "posts_per_page" \u003d\u003e -1); $ loop \u003d new WP_Query ($ args); while ($ loop-\u003e have_posts ()): $ loop-\u003e the_post (); get_template_part ("include / tax-item"); endwhile; ?\u003e

    get_template_part ("include / tax-item"); - in the tax-item.php file, I output the post content that I need to display the posts inside the loop (title, thumbnail, date, quote, etc.)

    This option displays all Articles posts on the page, regardless of taxonomies (categories).

    And if we need to display each category separately with our news, then we use the first option described above.

    That being said, if you use the Yoast SEO plugin and use its breadcrumbs:

    Then when you select the "Articles Category" taxonomy in the plugin settings in "Taxonomy to show in breadcrumbs for post types", in breadcrumbs you will receive a link to the category to which the News belongs; with other options for displaying custom posts, this could not be done.