WordPress.org

Ready to get started?Download WordPress

Forums

PHP in variable? (7 posts)

  1. arthurdent2003
    Member
    Posted 3 years ago #

    Hi there - i have a question about php.

    I use "smooth slider" old version and I'd like to have something that calls a custom field.

    I've found the code where I'd love to let the custom field show up. But after hours, I don't get it to work. I think it's just an easy noob mistake:

    Here is the code:

    $html .=  sslider_get_the_image($img_args);
    
    		if(!$smooth_slider['content_limit'] or $smooth_slider['content_limit'] == '' or $smooth_slider['content_limit'] == ' ')
    		  $slider_excerpt = substr($slider_content,0,$smooth_slider['content_chars']);
    		else
    		  $slider_excerpt = smooth_slider_word_limiter( $slider_content, $limit = $smooth_slider['content_limit'] );
    
    		if ($smooth_slider['image_only'] == '1') {
    			$html .= '<!-- /smooth_slideri -->
    			</div>';
    		}
    		else {
    		   if($permalink!='') {
    			$html .= '<h2 ><a href="'.$permalink.'">'.$post_title.'</a></h2><span> '.$slider_excerpt.'</span>
    				<p class="more"><a href="'.$permalink.'">'.$smooth_slider['more'].'</a></p>
    
    				<!-- /smooth_slideri -->
    			</div>'[....]

    I tried to make something like $mymeta = get_post_meta($post->ID, "mycustomfield", true); and I wanted to have it in the Title:

    `.$post_title.'</a></h2><span>'

    So I wrote it like this:
    .$post_title.'</a></h2>'.$mymeta.'<span>' but it doesn't work. I can't see anything on the frontend.

    So my question: how can I put "php" into this code to show my custom field value right next to the Title??

    Thank you!!!

    AD

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    It would go something like this..

    //
    		$mymeta = get_post_meta( $post->ID, "mycustomfield", true );
    		$html .= '<h2><a href="'.$permalink.'">'.$post_title.'</a>'.$mymeta.'</h2><span> '.$slider_excerpt.'</span>
    		<p class="more"><a href="'.$permalink.'">'.$smooth_slider['more'].'</a></p>
    		<!-- /smooth_slideri -->
    		</div>'

    However, i'm not sure you have $post (you'll need it to use $post->ID) available to you(hard to tell without seeing more of the surrounding code), which may be the issue, if you do then the above should help.

  3. arthurdent2003
    Member
    Posted 3 years ago #

    thats the original Part in the code:

    [code moderated per forum rules - please use the pastebin for any code longer than 10 lines;
    i also deleted your previous post because of the code overload; if that code was important, please use the pastebin]

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    Wow, that's alot of code, unfortunately there seems to be a bug that prevents me from trimming it from your reply(odd)..

    As far as i can see you should be able to reference $post_id instead of $post->ID, and that should solve the problem.. :)

    If you can edit the above(not the reply directly above, the huge one before that), please do so and remove the code, then place it into a pastebin please.

  5. arthurdent2003
    Member
    Posted 3 years ago #

    As far as i can see you should be able to reference $post_id instead of $post->ID, and that should solve the problem.. :)

    yes! that's it! Thank you very much! I was really getting nuts :-)

    I tried to edit the post above, after I saw that's a bit too long, but I can't - the post is not showing up...sorry for that! I'll try it again!

    Thank you for your help!!!

    AD

  6. Mark / t31os
    Moderator
    Posted 3 years ago #

    Happy to help, and looks like another mod removed the code overflow for us.. :)

    Glad to hear you've got things working how you want them.. :)

  7. arthurdent2003
    Member
    Posted 3 years ago #

    Yes - thank you guys! :)

Topic Closed

This topic has been closed to new replies.

About this Topic