Quick PHP question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • incredibleworkethic
    Confirmed User
    • Sep 2009
    • 2298

    #1

    Tech 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
    Confirmed User
    • Aug 2005
    • 8619

    #2
    try
    Code:
    $str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';
    Use coupon 'pauljohn' for a $1 discount at already super cheap NameSilo!
    Anal Webcams | Kinky Trans Cams Live | Hotwife XXX Tube | Get your Proxies here

    Comment

    • EddyTheDog
      Just Doing My Own Thing
      • Jan 2011
      • 25433

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

      Comment

      • incredibleworkethic
        Confirmed User
        • Sep 2009
        • 2298

        #4
        Originally posted by Paul&John
        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.

        Comment

        • incredibleworkethic
          Confirmed User
          • Sep 2009
          • 2298

          #5
          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>';
                  }; 
          

          Comment

          • EddyTheDog
            Just Doing My Own Thing
            • Jan 2011
            • 25433

            #6
            Originally posted by incredibleworkethic
            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...

            Comment

            • incredibleworkethic
              Confirmed User
              • Sep 2009
              • 2298

              #7
              Originally posted by EddyTheDog
              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?

              Comment

              • incredibleworkethic
                Confirmed User
                • Sep 2009
                • 2298

                #8
                Originally posted by Paul&John
                try
                Code:
                $str .= '<div class="thumb-wrap"><a href="'.the_field('url').'">';
                So here's a visual of what happened:

                Comment

                • EddyTheDog
                  Just Doing My Own Thing
                  • Jan 2011
                  • 25433

                  #9
                  Originally posted by incredibleworkethic
                  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.....

                  Comment

                  • incredibleworkethic
                    Confirmed User
                    • Sep 2009
                    • 2298

                    #10
                    OK thanks I'll give it a try.

                    Comment

                    • incredibleworkethic
                      Confirmed User
                      • Sep 2009
                      • 2298

                      #11
                      Tried, still giving the same result.

                      Interesting problem for sure.

                      Comment

                      • redwhiteandblue
                        Bollocks
                        • Jun 2007
                        • 2785

                        #12
                        Try echoing out the_field('url') to see what it produces. If it echoes out the url you want, the problem is elsewhere.
                        Interserver unmanaged AMD Ryzen servers from $73.00

                        Comment

                        • Barry-xlovecam
                          It's 42
                          • Jun 2010
                          • 18083

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

                          Comment

                          • incredibleworkethic
                            Confirmed User
                            • Sep 2009
                            • 2298

                            #14
                            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.

                            Comment

                            • Barry-xlovecam
                              It's 42
                              • Jun 2010
                              • 18083

                              #15
                              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

                              Comment

                              • sarettah
                                see you later, I'm gone
                                • Oct 2002
                                • 14336

                                #16
                                Originally posted by incredibleworkethic
                                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.

                                .
                                All cookies cleared!

                                Comment

                                • marlboroack
                                  So Fucking Banned
                                  • Jul 2010
                                  • 9327

                                  #17
                                  skype me really quick I'll do it

                                  Comment

                                  • sarettah
                                    see you later, I'm gone
                                    • Oct 2002
                                    • 14336

                                    #18
                                    Originally posted by marlboroack
                                    skype me really quick I'll do it
                                    Yeah, like anyone would let you into their server.

                                    Go away scammer.

                                    .
                                    All cookies cleared!

                                    Comment

                                    • Colmike9
                                      (>^_^)b
                                      • Dec 2011
                                      • 7217

                                      #19
                                      +1 for Sarettah.

                                      If you still need help, email me and I'll figure it out later tonight.
                                      Join the BEST cam affiliate program on the internet!
                                      I've referred over $1.7mil in spending this past year, you should join in.
                                      I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..

                                      Comment

                                      • incredibleworkethic
                                        Confirmed User
                                        • Sep 2009
                                        • 2298

                                        #20
                                        Originally posted by sarettah
                                        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!

                                        Comment

                                        • sarettah
                                          see you later, I'm gone
                                          • Oct 2002
                                          • 14336

                                          #21
                                          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/

                                          .
                                          All cookies cleared!

                                          Comment

                                          • RyuLion
                                            • Mar 2003
                                            • 32369

                                            #22
                                            Originally posted by sarettah
                                            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!!

                                            Adult Biz Consultant A tech head since 1995
                                            Affiliate Support: Chaturbate | CCBill Live

                                            Comment

                                            • Bladewire
                                              StraightBro
                                              • Aug 2003
                                              • 56220

                                              #23
                                              Originally posted by sarettah
                                              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!


                                              Skype: CallTomNow

                                              Comment

                                              • blackmonsters
                                                Making PHP work
                                                • Nov 2002
                                                • 21005

                                                #24
                                                Originally posted by sarettah
                                                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/

                                                .

                                                For sale : foslacs.com

                                                https://gfy.com/forum/your-business-needs/sell-and-buy-forum/31465316-foslacs-com-for-sale-all-rights-to-the-software-included

                                                Comment

                                                • Struggle4Bucks
                                                  Sieg Hi!
                                                  • May 2011
                                                  • 3615

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

                                                  I'm out...
                                                  Half troll half amazing!

                                                  Comment

                                                  • incredibleworkethic
                                                    Confirmed User
                                                    • Sep 2009
                                                    • 2298

                                                    #26
                                                    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!

                                                    Comment

                                                    • sarettah
                                                      see you later, I'm gone
                                                      • Oct 2002
                                                      • 14336

                                                      #27
                                                      Originally posted by Struggle4Bucks
                                                      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

                                                      .
                                                      All cookies cleared!

                                                      Comment

                                                      • sarettah
                                                        see you later, I'm gone
                                                        • Oct 2002
                                                        • 14336

                                                        #28
                                                        Originally posted by incredibleworkethic
                                                        Poo threads by currentlysober are great too!
                                                        GFY, your source for PHP and POO

                                                        .
                                                        All cookies cleared!

                                                        Comment

                                                        Working...