Support » Plugins » Hacks » PHP in variable?

  • 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']);
    		  $slider_excerpt = smooth_slider_word_limiter( $slider_content, $limit = $smooth_slider['content_limit'] );
    		if ($smooth_slider['image_only'] == '1') {
    			$html .= '<!-- /smooth_slideri -->
    		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 -->

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


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


Viewing 6 replies - 1 through 6 (of 6 total)
  • 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 -->

    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.

    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]

    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.

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


    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.. 🙂

    Yes – thank you guys! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP in variable?’ is closed to new replies.