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
  • Whenever in doubt about a WordPress function, check the Codex, get_page_by_title, there you'd have found the correct function EAMann is referencing bellow. And checking the documentation of get_page will solve the doubt you are commenting about... – brasofilo Commented Feb 11, 2013 at 21:42
Add a comment  | 

2 Answers 2

Reset to default 0

That'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