GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Quick PHP question (https://gfy.com/showthread.php?t=1238845)

incredibleworkethic 01-11-2017 12:44 AM

Quick PHP question
 
$str .= '<div class="thumb-wrap"><a href="<?php the_field('url'); ?>">';


I know I'm a newb, but this line breaks my code.

Is there a way to call a field "URL" (advanced custom fields) within a string of PHP?

If I hardcode the URL instead of that line of PHP, I can achieve what I want but I'm pulling it from a post because each url is pulled from a custom field.

Paul&John 01-11-2017 12:51 AM

try
Code:

$str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';

EddyTheDog 01-11-2017 12:59 AM

Yeah - It's a quotes thing I'm sure - Need more coffee...

incredibleworkethic 01-11-2017 12:59 AM

Quote:

Originally Posted by Paul&John (Post 21442489)
try
Code:

$str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';

it's now giving me the blog posts url instead of the custom field's data

Thanks so much for the quick response.

incredibleworkethic 01-11-2017 01:05 AM

This is me basically trying to link the featured image. Usually templates allow me to hardcode the featured image but this thing is deeply embedded.

PHP Code:

            $str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';
            if ( 
'gallery' == get_post_format$post->ID ) ) {
                
$str .= tn_moduleSingleSlider$post->ID$options['style'] );
            } elseif ( 
function_exists"has_post_thumbnail" ) && has_post_thumbnail$post->ID ) ) {
                
$featured_thumb tn_get_theme_option'tn_single_post_featured_image' );
                switch ( 
$featured_thumb ) {
                    case  
'full' :
                        
$str .= get_the_post_thumbnail$post->ID'native-image-thumb' );
                        break;
                    case 
'hide' :
                        
$str .= '';
                        break;
                    default:
                        
$str .= get_the_post_thumbnail$post->ID'blog_classic_thumb' );
                };
            }
            
$str .= '</a></div>';
        }; 


EddyTheDog 01-11-2017 01:09 AM

Quote:

Originally Posted by incredibleworkethic (Post 21442504)
it's now giving me the blog posts url instead of the custom field's data

Thanks so much for the quick response.

url will just give the current page address - Try using myURL or something like that...

incredibleworkethic 01-11-2017 01:17 AM

Quote:

Originally Posted by EddyTheDog (Post 21442513)
url will just give the current page address - Try using myURL or something like that...

I'm using advanced custom fields, so they tell us to use the_field (calling the plugin's fields) and the field within the plugin called URL.

To simply my question, I've also added "url" as a custom field in the wordpress post. Any idea how to call on that within my original question?

incredibleworkethic 01-11-2017 01:17 AM

Quote:

Originally Posted by Paul&John (Post 21442489)
try
Code:

$str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';

So here's a visual of what happened:

http://image.prntscr.com/image/f6517...a48bc8aa52.png

EddyTheDog 01-11-2017 01:24 AM

Quote:

Originally Posted by incredibleworkethic (Post 21442534)
I'm using advanced custom fields, so they tell us to use the_field (calling the plugin's fields) and the field within the plugin called URL.

To simply my question, I've also added "url" as a custom field in the wordpress post. Any idea how to call on that within my original question?

Change URL in the custom field to myURL (or whatever) - Then use that...

Still only had 2 coffees so could be wrong:upsidedow.....

incredibleworkethic 01-11-2017 05:21 AM

OK thanks I'll give it a try:).

incredibleworkethic 01-11-2017 10:04 AM

Tried, still giving the same result.

Interesting problem for sure.

redwhiteandblue 01-11-2017 10:12 AM

Try echoing out the_field('url') to see what it produces. If it echoes out the url you want, the problem is elsewhere.

Barry-xlovecam 01-11-2017 10:40 AM

$url needs to be the location of a read of the data maybe. Then $data1 becomes the string or array of the data.

incredibleworkethic 01-11-2017 11:40 AM

Anyone want a few bucks to make this happen for me? I can't get it to work and I really like the theme lol.

Barry-xlovecam 01-11-2017 11:46 AM

PHP: file_get_contents - Manual

try this

file() - Reads entire file into an array
fgets() - Gets line from file pointer
fread() - Binary-safe file read
readfile() - Outputs a file
file_put_contents() - Write a string to a file
stream_get_contents() - Reads remainder of a stream into a string
stream_context_create() - Creates a stream context
$http_response_header

sarettah 01-11-2017 11:48 AM

Quote:

Originally Posted by incredibleworkethic (Post 21443995)
Anyone want a few bucks to make this happen for me? I can't get it to work and I really like the theme lol.

I sent you a pm.

.

marlboroack 01-11-2017 12:11 PM

skype me really quick I'll do it

sarettah 01-11-2017 12:14 PM

Quote:

Originally Posted by marlboroack (Post 21444100)
skype me really quick I'll do it

Yeah, like anyone would let you into their server.

Go away scammer.

.

Colmike9 01-11-2017 12:26 PM

+1 for Sarettah.

If you still need help, email me and I'll figure it out later tonight. :upsidedow

incredibleworkethic 01-11-2017 01:05 PM

Quote:

Originally Posted by sarettah (Post 21444028)
I sent you a pm.

.

Thanks to each and everyone for their help.

Sarettah is more than kind and good karma should be hitting him often in his lifetime!

He identified an error on my end, even though everyone's ideas were legit.

Thanks again! :pimp:pimp:pimp

sarettah 01-11-2017 01:19 PM

Hey,

You r welcome but I should have been able to do that without having you send me the file. lol. I ran into something very similar a while back on something I was working on but forgot about it until I was looking at the file.

For the record in case anyone searches on this at some point:

The problem was that the wrong function was being used.

the_field() echoes the value in the field to the page.

get_field() pulls in the value.

So the change was changing the_field() to get_field() and it all worked as expected.

https://www.advancedcustomfields.com...ces/the_field/

.

RyuLion 01-11-2017 02:23 PM

Quote:

Originally Posted by sarettah (Post 21444370)
Hey,

You r welcome but I should have been able to do that without having you send me the file. lol. I ran into something very similar a while back on something I was working on but forgot about it until I was looking at the file.

For the record in case anyone searches on this at some point:

The problem was that the wrong function was being used.

the_field() echoes the value in the field to the page.

get_field() pulls in the value.

So the change was changing the_field() to get_field() and it all worked as expected.

https://www.advancedcustomfields.com...ces/the_field/

.

Woot woot!!

Bladewire 01-11-2017 02:52 PM

Quote:

Originally Posted by sarettah (Post 21444370)
Hey,

You r welcome but I should have been able to do that without having you send me the file. lol. I ran into something very similar a while back on something I was working on but forgot about it until I was looking at the file.

For the record in case anyone searches on this at some point:

The problem was that the wrong function was being used.

the_field() echoes the value in the field to the page.

get_field() pulls in the value.

So the change was changing the_field() to get_field() and it all worked as expected.

https://www.advancedcustomfields.com...ces/the_field/

.

You are awesome!

blackmonsters 01-11-2017 03:48 PM

Quote:

Originally Posted by sarettah (Post 21444370)
Hey,

You r welcome but I should have been able to do that without having you send me the file. lol. I ran into something very similar a while back on something I was working on but forgot about it until I was looking at the file.

For the record in case anyone searches on this at some point:

The problem was that the wrong function was being used.

the_field() echoes the value in the field to the page.

get_field() pulls in the value.

So the change was changing the_field() to get_field() and it all worked as expected.

https://www.advancedcustomfields.com...ces/the_field/

.


:thumbsup:thumbsup

Struggle4Bucks 01-11-2017 04:59 PM

When I read "php" I always get a headache...
Usually 2 weeks later another headache because of the invoice...

I'm out...

incredibleworkethic 01-11-2017 05:09 PM

This is the best part of gfy. I've met some great people here. Keep your head out of the shit threads and you're good. Poo threads by currentlysober are great too!

sarettah 01-11-2017 07:41 PM

Quote:

Originally Posted by Struggle4Bucks (Post 21444937)
When I read "php" I always get a headache...
Usually 2 weeks later another headache because of the invoice...

I'm out...

I can get rid of that 2 week later headache for you.

I bill in advance ;p

.

sarettah 01-11-2017 07:42 PM

Quote:

Originally Posted by incredibleworkethic (Post 21444970)
Poo threads by currentlysober are great too!

GFY, your source for PHP and POO :thumbsup

.


All times are GMT -7. The time now is 01:13 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc