![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Aug 2009
Posts: 274
|
![]() I have a custom field called XYZ with url and I need to put that url in theme template (footer), outside the loop - like this: <a href="XYZ value">some example text</a>
When I call this custom field: <a href="<?php echo get_post_meta($post->ID, 'XYZ', true); ?>">some example text</a> it just shows <a href="current posts permalink">some example text</a> So how to do that properly? ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
marketer.
Industry Role:
Join Date: Aug 2006
Location: bcn
Posts: 2,280
|
if u need to do it outside the loop with post->id u need to do the_post() - you doing that? it shouldn't be showing the permalink though in any case. sure the XYZ value is set up correctly? inside the loop does it show the right value?
if u use the post inside the loop (and always will) why not just do this inside the loop $footerData = get_post_meta(get_the_ID(), 'XYZ', true); (get_the_ID() can be changed with $post->ID...) then in the footer just <?=$footerData;?> it (not checked any code... might be errors) |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Too lazy to set a custom title
Industry Role:
Join Date: Aug 2002
Posts: 55,232
|
Quote:
you will need to pass the actual post id outside the loop for the footer. and if you are changing it each post, i would store the postid in a variable then pass that on to the footer code.
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence. ![]() WP Stuff |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Aug 2009
Posts: 274
|
Ok guys, thank a lot for the info.
I found the solution, maybe someone will find it useful too: Displaying Custom Fields Outside The Loop There are times, when you need to display custom fields outside the loop, e.g., in the footer of the blog post. Displaying custom fields outside the loop will allow you, for example, to have a different footer for each blog post. To achieve, this two things need to be done. 1. Edit the blog post template (e.g., single.php) to make post ID available outside the loop. Find the line Code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> Code:
<?php $GLOBALS['current_id'] = $post->ID; ?> Code:
<?php echo get_post_meta($GLOBALS['current_id'], "custom-field-name", true); ?> source (through google cache) |
![]() |
![]() ![]() ![]() ![]() ![]() |