
{"id":1156,"date":"2012-11-23T12:32:51","date_gmt":"2012-11-23T12:32:51","guid":{"rendered":"http:\/\/congnghepc.com\/2012\/11\/23\/hien-thi-bai-viet-lien-quan-ma-khong-can-dung-plugin-trong-wordpress\/"},"modified":"2025-06-20T16:41:21","modified_gmt":"2025-06-20T09:41:21","slug":"hien-thi-bai-viet-lien-quan-ma-khong-can-dung-plugin-trong-wordpress","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/hien-thi-bai-viet-lien-quan-ma-khong-can-dung-plugin-trong-wordpress\/","title":{"rendered":"Hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft li\u00ean quan m\u00e0 kh\u00f4ng c\u1ea7n d\u00f9ng plugin trong wordpress"},"content":{"rendered":"\n<p>Trong b\u00e0i vi\u1ebft n\u00e0y m\u00ecnh c\u00f3 2 l\u1ef1a ch\u1ecdn d\u00e0nh cho b\u1ea1n:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">L\u1ea5y b\u00e0i vi\u1ebft theo th\u1ebb Tag<\/h3>\n\n\n\n<p>Hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft li\u00ean quan d\u1ef1a tr\u00ean c\u00e1c th\u1ebb tag c\u1ee7a b\u00e0i vi\u1ebft<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n    \/\/L\u1ea5y danh s\u00e1ch c\u00e1c th\u1ebb tag t\u1eeb b\u00e0i vi\u1ebft\n    $tags = wp_get_post_tags($post-&gt;ID);\n    \/\/N\u1ebfu tags t\u1ed3n t\u1ea1i th\u00ec.\n    if ($tags) {\n        $tag_ids = array();\n        \/\/L\u1ea5y gi\u00e1 tr\u1ecb id c\u1ee7a tag\n        foreach($tags as $each_tag) $tag_ids&#x5B;] = $each_tag-&gt;term_id;\n        \/\/WP_Query arguments.\n        $args = array(\n            &#039;tag__in&#039; =&gt; $tag_ids, \/\/M\u1ed9t m\u1ea3ng c\u1ee7a tag IDs s\u1ebd \u0111\u01b0\u1ee3c \u0111\u01b0a v\u00e0o.\n            &#039;post__not_in&#039; =&gt; array($post-&gt;ID), \/\/M\u1ed9t m\u1ea3ng c\u1ee7a ID b\u00e0i vi\u1ebft s\u1ebd \u0111\u01b0\u1ee3c lo\u1ea1i tr\u1eeb.\n            &#039;orderby&#039;=&gt; &#039;rand&#039;, \/\/Hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft ng\u1eabu nhi\u00ean\n            &#039;showposts&#039; =&gt; 10, \/\/ S\u1ed1 l\u01b0\u1ee3ng b\u00e0i vi\u1ebft m\u00e0 b\u1ea1n mu\u1ed1n hi\u1ec3n th\u1ecb\n            \/\/&#039;caller_get_posts&#039; =&gt; 1 \/\/ s\u1eed d\u1ee5ng n\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng wordpress phi\u00ean b\u1ea3n\u00a0 &lt; 3.1 ***\n            &#039;ignore_sticky_posts&#039; =&gt; 1 \/\/*** s\u1eed d\u1ee5ng cho phi\u00ean b\u1ea3n wordpress &gt;= 3.1 ***\n        );\n        $query = new WP_Query($args);\n        \/\/N\u1ebfu c\u00f3 nh\u1eefng b\u00e0i vi\u1ebft li\u00ean quan th\u00ec\n        if( $query-&gt;have_posts() ) {\n            echo &#039;&lt;div&gt;&#039;;\n                echo &#039;&lt;h3&gt;Related Article(s):&lt;\/h3&gt;&#039;; \/\/*** Thay \u0111\u1ed5i ti\u00eau \u0111\u1ec1 theo \u00fd b\u1ea1n***\n                echo &#039;&lt;ol&gt;&#039;;\n                    while ($query-&gt;have_posts()) { $query-&gt;the_post(); ?&gt;\n                    &lt;li&gt;\n                        &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to: &lt;?php the_title_attribute(); ?&gt;&quot;&gt;\n                            &lt;?php the_title(); ?&gt;\n                        &lt;\/a&gt;\n                    &lt;\/li&gt;\n                    &lt;?php }\n                echo &#039;&lt;\/ol&gt;&#039;;\n            echo &#039;&lt;\/div&gt;&#039;;\n        }\n    }\n\/\/ H\u1ee7y chu\u1ed7i query tr\u01b0\u1edbc \u0111\u00f3\nwp_reset_query();\n?&gt;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">L\u1ea5y b\u00e0i vi\u1ebft theo Category<\/h3>\n\n\n\n<p>Hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft li\u00ean quan d\u1ef1a tr\u00ean danh m\u1ee5c c\u1ee7a b\u00e0i vi\u1ebft (category).<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nif ($categories) {\n\n    $category_ids = array();\n    \/\/retrieve the category_ids for the post.\n    foreach($categories as $each_category) $category_ids&#x5B;] = $each_category-&gt;term_id;\n\n    \/\/WP_Query arguments.\n    $args = array(\n        &#039;tag__in&#039; =&gt; $tag_ids, \/\/M\u1ed9t m\u1ea3ng c\u1ee7a tag IDs s\u1ebd \u0111\u01b0\u1ee3c \u0111\u01b0a v\u00e0o.\n        &#039;post__not_in&#039; =&gt; array($post-&gt;ID), \/\/M\u1ed9t m\u1ea3ng c\u1ee7a ID b\u00e0i vi\u1ebft s\u1ebd \u0111\u01b0\u1ee3c lo\u1ea1i tr\u1eeb.\n        &#039;orderby&#039;=&gt; &#039;rand&#039;, \/\/Hi\u1ec3n th\u1ecb b\u00e0i vi\u1ebft ng\u1eabu nhi\u00ean\n        &#039;showposts&#039; =&gt; 10, \/\/ S\u1ed1 l\u01b0\u1ee3ng b\u00e0i vi\u1ebft m\u00e0 b\u1ea1n mu\u1ed1n hi\u1ec3n th\u1ecb\n        \/\/&#039;caller_get_posts&#039; =&gt; 1 \/\/ s\u1eed d\u1ee5ng n\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng wordpress phi\u00ean b\u1ea3n\u00a0 &lt; 3.1 ***\n        &#039;ignore_sticky_posts&#039; =&gt; 1 \/\/*** s\u1eed d\u1ee5ng cho phi\u00ean b\u1ea3n wordpress &gt;= 3.1 ***\n    );\n    $query = new WP_Query($args);\n\n    \/\/ N\u1ebfu c\u00f3 nh\u1eefng b\u00e0i vi\u1ebft li\u00ean quan th\u00ec\n    if( $query-&gt;have_posts() ) {\n        echo &#039;&lt;div&gt;&#039;;\n            echo &#039;&lt;h3&gt;Related Article(s):&lt;\/h3&gt;&#039;; \/\/*** Thay \u0111\u1ed5i ti\u00eau \u0111\u1ec1 theo \u00fd b\u1ea1n***\n            echo &#039;&lt;ol&gt;&#039;;\n                while ($query-&gt;have_posts()) {  $query-&gt;the_post(); ?&gt;\n                    &lt;li&gt;\n                        &lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to: &lt;?php the_title_attribute(); ?&gt;&quot;&gt;\n                            &lt;?php the_title(); ?&gt;\n                        &lt;\/a&gt;\n                    &lt;\/li&gt;\n                &lt;?php }\n            echo &#039;&lt;\/ol&gt;&#039;;\n        echo &#039;&lt;\/div&gt;&#039;;\n    }\n}\n\/\/ H\u1ee7y chu\u1ed7i query tr\u01b0\u1edbc \u0111\u00f3\n    wp_reset_query();\n?&gt;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Hi\u1ec7n th\u1ecb tr\u00ean website<\/h3>\n\n\n\n<p>Sau khi b\u1ea1n quy\u1ebft \u0111\u1ecbnh l\u1ef1a ch\u1ecdn c\u1ee7a m\u00ecnh, th\u00ec copy v\u00e0 paste code t\u01b0\u01a1ng \u1ee9ng v\u00e0o file single.php. File n\u00e0y n\u1eb1m trong folder theme m\u00e0 b\u1ea1n \u0111ang s\u1eed d\u1ee5ng.<\/p>\n\n\n\n<p>\u0110o\u1ea1n code ph\u1ea3i \u0111\u01b0\u1ee3c \u0111\u1eb7t b\u00ean d\u01b0\u1edbi h\u00e0m <strong>the_content()<\/strong> nh\u01b0 \u0111o\u1ea1n code minh h\u1ecda b\u00ean d\u01b0\u1edbi:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php get_header(); ?&gt;\n\n&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;\n    &lt;div &lt;?php post_class() ?&gt; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;\n\n        &lt;div&gt;\n            &lt;span&gt;&lt;?php the_time(&#039;d&#039;) ?&gt;&lt;\/span&gt;&lt;br \/&gt;\n            &lt;span&gt;&lt;?php the_time(&#039;M&#039;) ?&gt;&lt;\/span&gt;&lt;br \/&gt;\n            &lt;span&gt;&lt;?php the_time(&#039;Y&#039;) ?&gt;&lt;\/span&gt;\n        &lt;\/div&gt;\n\n        &lt;div&gt;\n            &lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;Permanent Link to &lt;?php the_title_attribute(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h2&gt;\n        &lt;div&gt;\n\n        &lt;?php the_content(&#039;Read the rest of this entry &amp;raquo;&#039;); ?&gt;\n\n        &lt;?php \/*Ph\u1ea7n ph\u00e2n trang n\u1eb1m \u1edf \u0111\u00e2y. *\/ wp_link_pages(array(&#039;before&#039; =&gt; &#039;&lt;p&gt;&lt;span&gt;Pages:&lt;\/span&gt; &#039;, &#039;after&#039; =&gt; &#039;&lt;\/p&gt;&#039;, &#039;next_or_number&#039; =&gt; &#039;number&#039;)); ?&gt;\n\n    &lt;\/div&gt;\n\n    &lt;!-- \u0110\u00e2y l\u00e0 n\u01a1i b\u1ea1n s\u1ebd \u0111\u1eb7t \u0111o\u1ea1n code m\u00e0 b\u1ea1n mu\u1ed1n hi\u1ec3n th\u1ecb K\u1ebft th\u00fac \u0111o\u1ea1n code \u1edf \u0111\u00e2y\u00a0 --&gt;\n    \n    &lt;div&gt;\n        &lt;?php comments_template(); ?&gt;\n    &lt;\/div&gt;\n\n&lt;?php endwhile; else: ?&gt;\n    &lt;p id=&quot;rightcolumn&quot;&gt;Sorry, no posts matched your criteria.&lt;\/p&gt;\n&lt;?php endif; ?&gt;\n\n&lt;?php get_sidebar(); ?&gt;\n\n&lt;?php get_footer(); ?&gt;\n<\/pre><\/div>\n\n\n<p class=\"has-text-align-right\"><strong>Ch\u00fac c\u00e1c b\u1ea1n th\u00e0nh c\u00f4ng !<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trong b\u00e0i vi\u1ebft n\u00e0y m\u00ecnh c\u00f3 2 l\u1ef1a ch\u1ecdn d\u00e0nh cho b\u1ea1n: L\u1ea5y b\u00e0i vi\u1ebft theo th\u1ebb Tag Hi\u1ec3n th\u1ecb [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":6979,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[143],"tags":[],"class_list":["post-1156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thu-thuat-wordpress"],"views":431,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/1156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=1156"}],"version-history":[{"count":11,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/1156\/revisions"}],"predecessor-version":[{"id":9901,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/1156\/revisions\/9901"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/6979"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=1156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=1156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=1156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}