{"id":6236,"date":"2016-12-03T15:40:22","date_gmt":"2016-12-03T20:40:22","guid":{"rendered":"https:\/\/themespress.ca\/?p=6236"},"modified":"2022-09-04T08:21:02","modified_gmt":"2022-09-04T12:21:02","slug":"create-a-custom-link-for-your-template-pages","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/create-a-custom-link-for-your-template-pages\/","title":{"rendered":"Create a Custom Link for your Template Pages"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This tutorial will show you how to create a custom link for your template page: <strong>get_page_link<\/strong>.<\/p>\n<p>First thing we need to do is create our template page in the root folder of our WordPress theme.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Create a template page: For example: User Favorites<\/h2><div id=\"ts-enlighterjs-container-7040045\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7040045\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php\n\/**\n * Recent User Favorites\n *\n * This file contains the markup for recent entries displayed in the\n * 404 pages of the Prime theme.\n *\n * @package Nomdutheme\n *\/\n?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>The next step is creating the new page in WordPress Admin and associate it to the newly created template.<\/p>\n<p>We will use a query, Post type, to match with our template page with the  <strong>_wp_page_template<\/strong> meta Key and our template name as a value (Remplace <strong>user-profile.php<\/strong> by your template page). We will ask to return your page on demand.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2390455\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-2390455\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">function viadirectory_userprofile_id() {\n\t$args = [\n\t&#039;post_type&#039;     =&gt; &#039;page&#039;,\n\t&#039;fields&#039;        =&gt; &#039;ids&#039;,\n\t&#039;nopaging&#039;      =&gt; true,\n\t&#039;meta_key&#039;      =&gt; &#039;_wp_page_template&#039;,\n\t&#039;meta_value&#039;    =&gt; &#039;user-profile.php&#039;\n\t];\n\t$pages = get_posts( $args );\n\tforeach ( $pages as $page ) \n\treturn $page;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>We will now create our custom permalink in order to load up the desired template. You can also add a custom CSS styling.<\/p>\n<p>We will be using the <strong><a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/get_page_link\" target=\"_blank\" rel=\"noopener\">get_page_link<\/a><\/strong> function and include another function, viadirectory_userprofile_id(), which returns the page query.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-6639923\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-6639923\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;ul&gt;\n \t&lt;li style=&quot;list-style-type: none;&quot;&gt;\n \t&lt;li class=&quot;&lt;?php if (is_page_template(&#039;user-profile.php&#039;)) { echo &#039;active&#039;; } else {}; ?&gt;&quot;&gt;&lt;\/l&gt;\n&lt;\/ul&gt;\n<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You now have a dynamic link that loads the desired <a href=\"https:\/\/developer.wordpress.org\/themes\/template-files-section\/page-template-files\/page-templates\/\" target=\"_blank\" rel=\"noopener\">Template Page<\/a>.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"This tutorial will show you how to create a custom link for your template page: get_page_link. First thing we need to do is create our template page in the root<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/create-a-custom-link-for-your-template-pages\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4577,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[332,318,348],"class_list":["post-6236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-body","tag-functions","tag-themes-code"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6236"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6236\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4577"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}