{"id":3550,"date":"2017-09-09T09:35:37","date_gmt":"2017-09-09T09:35:37","guid":{"rendered":"https:\/\/ampforwp.com\/tutorials\/?post_type=ht_kb&#038;p=3550"},"modified":"2020-05-07T08:26:41","modified_gmt":"2020-05-07T08:26:41","slug":"related-posts","status":"publish","type":"ht_kb","link":"https:\/\/ampforwp.com\/tutorials\/article\/related-posts\/","title":{"rendered":"Related Posts"},"content":{"rendered":"\n<p>This article is for&nbsp;<a href=\"https:\/\/ampforwp.com\/amp-theme-framework\/\">AMP Theme Framework<\/a>&nbsp;users.<\/p>\n\n\n\n<h3>About this Component<\/h3>\n\n\n\n<p>Related Post Component is for displaying the related posts for the single in your AMP theme.<\/p>\n\n\n\n<h3>How to use:<\/h3>\n\n\n\n<p>Following are the steps to use this component.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong><\/p>\n\n\n\n<p>To initiate the support for the component in your theme just add the following code to the &#8220;<strong>functions.php<\/strong>&#8221; of the AMP Theme Framework directory.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">\/\/ Related Posts\nadd_amp_theme_support('AMP-related-posts');<\/pre><\/div>\n\n\n\n<p>This was the back-end part where we&#8217;ve just initiated, now to make it appear in the front-end follow the next step.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong><\/p>\n\n\n\n<p>To add the <strong>Related Post<\/strong>&nbsp;we need to call it.<br>example: add the following code in &#8220;<strong>single.php<\/strong>&#8221; of the AMP Theme Framework directory.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php amp_related_posts(); ?&gt;<\/pre><\/div>\n\n\n\n<p>with this, you&#8217;re successfully able to set&nbsp;<strong>Related Post<\/strong>&nbsp;on your theme.<\/p>\n\n\n\n<p>But By default, it will show Image and Excerpt in Related Posts. If you don&#8217;t want image or excerpt in Related Posts then you can hide them using the Arguments.<\/p>\n\n\n\n<p>Example: Add the following code to show Related Posts without Image and Excerpt.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$args = array('show_image'=&gt;false, 'show_excerpt'=&gt;false);\namp_related_posts($args);<\/pre><\/div>\n\n\n\n<p>You can also call separate parts of Related Posts inside the Query.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">\/\/ Query\n$my_query = related_post_loop_query();\n\n\/\/ Title\nampforwp_related_post();\n\n\/\/ Image\nampforwp_get_relatedpost_image();\n\n\/\/ Excerpt and Author\nampforwp_get_relatedpost_content();\n<\/pre><\/div>\n\n\n\n<p>But Wait, There&#8217;s more!<\/p>\n\n\n\n<p>You can even crop the image according to your need.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">ampforwp_get_relatedpost_image('full',array(\n                                     'image_crop'=&gt;'true',\n                                     'image_crop_width'=&gt;220,\n                                     'image_crop_height'=&gt;134) \n\n                               );<\/pre><\/div>\n\n\n\n<p>That&#8217;s all!<\/p>\n\n\n\n<p><strong>That\u2019s it for this tutorial!<\/strong><\/p>\n\n\n\n<p>We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.<\/p>\n<div id=\"div-1\" class=\"hkb-feedback\">\n\t\t\t<strong class=\"ht-mobile-exit__title\">Ask your Questions Directly!<\/strong><br>\n\t\t\t<div class=\"hkb_widget_exit__content\" style=\"font-size: 14px;\">If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!<\/div>\n\t\t\t<a href=\"https:\/\/ampforwp.com\/support\/#contact\" id=\"button\" target=\"_blank\" rel=\"noopener noreferrer\"><button>Yes, I have a Question<\/button><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>This article is for&nbsp;AMP Theme Framework&nbsp;users. About this Component Related Post Component is for displaying the related posts for the single in your AMP theme. How to use: Following are the steps to use this component. Step 1: To initiate the support for the component in your theme just add&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[185],"ht-kb-tag":[82],"_links":{"self":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/3550"}],"collection":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/comments?post=3550"}],"version-history":[{"count":8,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/3550\/revisions"}],"predecessor-version":[{"id":17262,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/3550\/revisions\/17262"}],"wp:attachment":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/media?parent=3550"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-category?post=3550"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-tag?post=3550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}