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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-09-2012, 06:13 AM   #1
madtwin
Confirmed User
 
Industry Role:
Join Date: Aug 2009
Posts: 274
WP Gurus - Help needed

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?
madtwin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-09-2012, 06:30 AM   #2
scouser
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)
scouser is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-09-2012, 07:22 AM   #3
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,232
Quote:
Originally Posted by deadmoon View Post
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)
get the id is only for the loop.

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
fris is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-09-2012, 11:38 AM   #4
madtwin
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(); ?>
and add the following code just below it:

Code:
<?php $GLOBALS['current_id'] = $post->ID; ?>
2. Use this code to display your custom field outside the loop, e.g., in the footer.php

Code:
<?php echo get_post_meta($GLOBALS['current_id'], "custom-field-name", true); ?>
That?s it! Now, when editing a blog post, add a custom field with ?custom-field-name? and it will display wherever you put that second bit of code.

source (through google cache)
madtwin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.