- This topic is empty.
-
AuthorPosts
-
September 24, 2009 at 6:12 pm #26234
minuscircus
MemberI am creating a post template in my wordpress.
I need to have:
1/ a dynamic src inside an image – so I can place "artist-image" as custom field and the path. This works.
2/ I need to a link underneath that contains a website link
3/ pretty much the same as number 2Here’s my PHP – 2 and 3 aren’t working – but number 1 is. What am I doing wrong? Any ideas?
<!– I NEED TO POST AN IMAGE FROM THE IMG and THEN TWO SEPERATE LINKS BELOW – 1/ WEBSITE 2/ MYSPACE URL –>
<div class="artist-details">
<?php
$artistimageCode = get_post_meta ($post ->ID, ‘artist-image’, true);
$websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
$myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
?><img src="<?php echo $artistimageCode; ?>" width="200" height="250" alt="music box for life artist" />
<p>Website: <a href="<?php echo $websiteCode; ?>" target="_blank"></a></p>
<p>Myspace: <a href="<?php echo $myspaceCode; ?>" target="_blank"></a></p>
</div>
<!– artist details close –><!– ARTIST CLOSE –>
September 24, 2009 at 6:51 pm #64655TheDoc
Member*Moved to CMS section since it’s dealing with Custom Fields*
I don’t think I can answer this without a little more information. What is it outputting that "isn’t working"? If you have a link to the page that’s doing it, that’d help too.
Also, you might want to consider changing the code slightly. What if the artist doesn’t have a Myspace page? I would do something like this:
Code:This way, if they don’t have a website, it won’t show "Website: ", it’ll just bump the Myspace up one line.
September 24, 2009 at 11:24 pm #64671minuscircus
MemberHey DOC
I didnt know where the post went – so I reposted after searching for it!
Thank for the suggestion – this is more of testing the water ie custom fields. Every artist involved the project with have a website and a myspace page. The problem is when I try to ADD a custom field in the backend of WP it says "An unidentified error has occured".
So let’s say this is what I wanted:
Code:ID, ‘artist-image’, true);
$websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
$myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
?>September 24, 2009 at 11:47 pm #64672TheDoc
MemberI’ve never heard of WP doing that, might be a problem with your install. You should technically be allowed to have unlimited custom fields. If you try deleting your first custom field and adding another, what happens?
September 25, 2009 at 6:48 am #64696minuscircus
Memberhey DOC
This really stumped me too – as my scripting looked to be pretty much ok. But I’ve fixed it – it must have been some weird little bug in my system.
I updated my version of WP to the latest (just in case 2.83 > 2.84) and deleted all my previous entries for custom fields. I re-inputted them and it’s working! I have no idea what the exact cause was – but it was worth the try :-)
Thanks for that!
Have a great weekend!
September 26, 2009 at 12:31 am #64719minuscircus
MemberActually Doc,
I’ve coem back with my tail between my legs! I’m trying to do what you suggested ie with the "if" statement as some of the artists only have myspace accounts (and not band websites) – this is what i have and what is working for me at the moment (without the IF statement)
Code:ID, ‘artist-image’, true);
$websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
$myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
?>more info
” target=”_blank”>Visit Website
” target=”_blank”>Visit MyspaceMy attempt at implementing your code:
Code:Any ideas? Thanks :-/
September 26, 2009 at 11:57 am #64728Dominic
MemberI’m not all that good at php, but what you have done with Doc’s code looks ok to me!
I’m assuming the problem is that the links aren’t showing up at all?
I’m guessing you have some css styling on the anchor tags to give them height and width?
ie., you have this:rather than:
Code:echo ‘Website: Visit Website
‘;
Other than that, I sometimes find that my supposedly empty custom fields (when made using the flutter plugin) have blank characters in them.
So I use the following:I hope I haven’t led you up the garden path here. I’m pretty new to php.
September 26, 2009 at 12:12 pm #64729Dominic
MemberActually… ignore all that php stuff at the bottom. I’m almost certain the issue I hinted at is exclusively related to custom fields created with the flutter plugin.
Sorry :roll:AuthorPostsViewing 8 posts - 1 through 8 (of 8 total)- The forum ‘Back End’ is closed to new topics and replies.