admin管理员组文章数量:1122832
I'm trying to make a dynamic button that goes to portfolio page (no matter what ID/name it has), it's currently like this:
$portfolio_page = get_option('theme_portfolio_page');
$portfolio_pid = get_page_by_title($portfolio_page);
<a href="<?php echo get_option ('theme_portfolio_page') ?>">Voltar</a>
The problem is that it links based on the page name, and when it has space on the name it bugs... So I would need a code that links dynamically to the portfolio page by ID
When I try to change to get_page_by_id
FATAL ERROR: CALL TO UNDEFINED FUNCTION GET_PAGE_BY_ID() IN /HOME/DOMAIN/WWW/WP-CONTENT/THEMES/MYTHEME/PORTFOLIO-TEMPLATE.PHP ON LINE 46
I'm trying to make a dynamic button that goes to portfolio page (no matter what ID/name it has), it's currently like this:
$portfolio_page = get_option('theme_portfolio_page');
$portfolio_pid = get_page_by_title($portfolio_page);
<a href="<?php echo get_option ('theme_portfolio_page') ?>">Voltar</a>
The problem is that it links based on the page name, and when it has space on the name it bugs... So I would need a code that links dynamically to the portfolio page by ID
When I try to change to get_page_by_id
FATAL ERROR: CALL TO UNDEFINED FUNCTION GET_PAGE_BY_ID() IN /HOME/DOMAIN/WWW/WP-CONTENT/THEMES/MYTHEME/PORTFOLIO-TEMPLATE.PHP ON LINE 46
Share Improve this question asked Feb 11, 2013 at 20:54 Lucas BustamanteLucas Bustamante 2,3181 gold badge28 silver badges43 bronze badges 1 |2 Answers
Reset to default 0That's because get_page_by_id
isn't a function in WordPress.
You want get_page
.
Try using Custom fields.
1.Add the page Id as a custom field value, for example "page_id".
add the following to your template file
$post = get_post_meta( get_the_ID(), 'page_id', true );
Thus you will get the link of the page in $post
Then give this is in your anchor tag as href
<a href="<?php echo $post ?>" > Something</a>
Hope this solves your problem
本文标签: Link to Portfolio page by id instead of name
版权声明:本文标题:Link to Portfolio page by id instead of name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289040a1928221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_page_by_title
, there you'd have found the correct function EAMann is referencing bellow. And checking the documentation ofget_page
will solve the doubt you are commenting about... – brasofilo Commented Feb 11, 2013 at 21:42