Support Forum
This is all good but - a couple of points.
There should be no need whatsoever to use the output buffer. You should just be able to perform the $zip_code variable assignment without that.
Rather than using isset() I would recommend using empty(). More reliable as you have created the $zip_code variable so it does exist.
YELLOW
SWORDFISH
|
Hey VikingBrent, thanks for the help! Nice it serve others too.
Following you suggestion I came to this :
$ZipCode=sp_CustomProfileFieldsDisplay('Code ami ', $spThisPost->user_id);
if (!empty($ZipCode['Zip Code'])) {
echo '<p style="font-size: 80%;" class="spCenter">Zip Code : $ZipCode</p>';
}
But again it looks the the echo does not work BUT I see the ZipCode when not empty. So it seems the if is executed but the echo is not except that the variable $ZipCode is echoed?
That's because that is incorrect use of the variable.
If you want to embed a variable in a string of text like that then the whole string has to be in double quotes not single.
Use:
Zip Code : ' . $ZipCode . '
instead is easiest = or - swap all the quotes around.
YELLOW
SWORDFISH
|
However, I'm going to have to retract my previous post, as the code I shared is most certainly not working.
It appears to function as I saw the correct value stored in my custom field, displayed in the appropriate location in the spUserSection div. However, upon further scrutiny, I discovered that the custom field value was only being echoed in the user's first post in the topic. If the user has more than one reply, the custom field value is missing from all but the first entry.
I discovered that the variable is apparently not being defined at all. For troubleshooting purposes, I've stripped the code down to its barest form. Here's what I'm working with (these are the particulars from my own work, which is why there's no reference to the $ZipCode variable from prior posts):
$SteamID=sp_CustomProfileFieldsDisplay('Steam ID', $spThisPost->user_id);
echo 'Steam: ';
echo $SteamID;
What appears to be happening is the $SteamID from line 1 is being ignored entirely and the output that I'm seeing (in my first post in the topic) is coming from the sp_CustomProfileFieldsDisplay('Steam ID', $spThisPost->user_id); function.
The first echo which outputs the string "Steam:" is working as expected and showing up on every reply. But the second echo outputs nothing. So here is the result:
1ST POST
custom-field-valueSteam:
2ND POPST
Steam:
I double checked the code in a clean install of the css-only theme to verify that this wasn't the result of something I botched in my custom theme and the results are the same. As I stated before, I am a PHP novice so perhaps this is a simple syntax mistake.
To check myself, I copied SPQC's code from reply #22, changing the improperly embedded variable, and substituted my own custom field name. Again, I stripped the 'if' statement for the sake of simplicity and got the same result: The output of sp_CustomProfileFieldsDisplay('Steam ID', $spThisPost->user_id); is displayed on the first post only.
This code is being placed into the spTopicView.php file around line 112, before the start of the user-identities section.
Any insight is most welcome.
I see VikingBrent have replied but still waiting moderation. You should subscribe! Maybe you have the answer?
Ok the echo don't work at all and the simple fact of having this line :
$ZipCode = sp_CustomProfileFieldsDisplay('Zip Code', $spThisPost->user_id);
output the zip code... I tried a few things but I'm out of ideas.
where are you guys putting this in your spTopicView template file?
also the template tag echos the output itself, so you cannot assign it to a variable... nothing is returned...
sp_CustomProfileFieldsDisplay('Zip Code', $spThisPost->user_id);
will just output the zip code stored for the user...
if you precede that with
echo 'zip: ';
you will end up with something like
zip: 54545
I put them right after:
sp_PostIndexUserName('tagClass=spPostUserName spCenter');
in my topic view to verify it works fine...
Visit Cruise Talk Central and Mr Papa's World
okay, a little secret... eh, not really... but there is an object that contains most of the data in this case being inside the post class with the $spThisPost user...
so in this case, you dont really have to use the template tag... its already in the user class... but we try to generically help...
so for this exact case, and not globally, just do:
if (!empty($spThisPostUser->zipcode)) echo 'zip: '.$spThisPostUser->zipcode;
you obviously could have replace the $spThisPostUser->zipcode; part with a call to the template tag... but since in our post loop, its already been prefilled...
Visit Cruise Talk Central and Mr Papa's World
Mr Papa said
so for this exact case, and not globally, just do:
if (!empty($spThisPostUser->zipcode)) echo 'zip: '.$spThisPostUser->zipcode;
hmmm.. I don't understand. Dunno if my english is the problem. Where is the call to properly target the desired CustumProfileField we want to display?
lol. not your English, but my knowledge of SP...
i just happen to know that whenever the user class object is loaded (in this case $spThisPostUser), we also load all user meta info including any custom profile fields into the user object... so
if (!empty($spThisPostUser->zipcode)) echo 'zip: '.$spThisPostUser->zipcode;
is the same as:
if (!empty($spThisPostUser->zipcode)) {
echo 'zip: ';
sp_CustomProfileFieldsDisplay('Zip Code', $spThisPost->user_id);
}
why? because as I said, we load the user object with all the info about that user... and the when you generate a slug from your custom field 'Zip Code', it becomse zipcode... so I can just grab it from the user object instead of using the template tag...
if you were ever to look at the object $spThisPostUser, you would see lots of data about that user...
Visit Cruise Talk Central and Mr Papa's World
1 Guest(s)