Wordpress: How to display a Custom Field in front end - advanced-custom-fields

I created an Custom Field using the plugin ACF. The field is type IMAGE.
I need to show the image in the frontend. I tried with this code, but it only show the POST ID of the image. I need to show the image or at least the image url.
/* PRINT CUSTOM FIELD*/
if(get_post_meta( get_the_ID(), 'MY_CUSTOM_FIELD_NAME', true )!= "" && get_post_meta( get_the_ID(), 'MY_CUSTOM_FIELD_NAME', true )!= "-"){
echo get_post_meta( get_the_ID(), 'MY_CUSTOM_FIELD_NAME', true );
}

Related

Passing down MediaWiki template arguments to custom HTML attributes

Consider a custom MediaWiki extension that adds a new tag named simplified_example with some JavaScript (just calling alert with provided argument for simplicity):
<?php
if ( ! defined( 'MEDIAWIKI' ) ) die();
$wgExtensionFunctions[] = 'registerTags';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'myTags',
);
function registerTags() {
global $wgParser;
$wgParser->setHook('simplified_example', function ($input, $argv, $parser, $frame) {
$output = $parser->recursiveTagParse($input, $frame);
$title = $argv["value"];
return "<div onclick=\"alert('$title')\">$output</div>";
});
}
?>
Using that I can put following code in a MediaWiki page source:
<simplified_example value="Testing">...</simplified_example>
This results with ... div being clickable - a message box with provided text is displayed. Now I wanted to place this tag inside a template, like this:
<simplified_example value="{{{1}}}">...</simplified_example>
When I put this template into a MediaWiki page:
{{TestTemplate|Testing...}}
Once again I obtain a clickable ... but displayed message is not evaluated and {{{1}}} is displayed instead of provided Testing....
How can I pass the argument from MediaWiki page source down to my custom tag through a template?
Try to use #tag function instead of html in your template, like this:
{{#tag:simplified_example|value={{{1}}} }}

Yii2 render image in browser without image tag using yii2-imagine

I'm using yii2-imagine
$imagine = yii\imagine\Image::getImagine();
Imagine->open('path/watermark.jpg')->show('jpg');
My problem is it not show the image, it show that:
����JFIF��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v90), default quality ��C $.' ",#(7),01444'9=82<.342��C 2!!22222222222222222222222222222222222222222222222222����"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�
Any idea?
You need to use the getImagine() function first to invoke the GD or Imagick which ever available instance then call ->open() and ->show() on the object. Moreover, you need to provide the $options for the image to display too. You can copy paste the following code inside an action in your controller and can see the result image. I just tested on my local system, and it is in working, just remember to provide valid path to the $source variable
use yii\imagine\Image;
$source="/path/to/your/image.jpg";
$imagine = new Image();
$options = array(
'resolution-units' => \Imagine\Image\ImageInterface::RESOLUTION_PIXELSPERINCH,
'resolution-x' => 300,
'resolution-y' => 300,
'jpeg_quality' => 100,
);
echo $imagine->getImagine()->open($source)->show('jpg',$options);
Apart from the above solution that displays the image in the browser if you want to display the image inside the img tag you can base64_encode the raw image data returned from the open() method and provide into the tag like below.
echo '<img src="data:image/jpeg;base64,'.base64_encode($imagine->getImagine()->open($source)).'" >';
Hope it helps

issue with image validator rules in laravel 4

I have defined this validating rule for a file(image) in laravel 4 .
'image' => 'image|mimes:jpeg,jpg,bmp,png,gif'
And this is my html code:
{{ Form::label('Image of the product') }} {{ Form::file('image') }}
now , I always get 2 errors while uploading an image even If I chose a png, jpg image
The image must be an image.
The image must be a file of type: jpeg, jpg, bmp, png, gif.
this is the update action that includes image upload :
public function update($id)
{
$product = Product::find($id);
$validator = Validator::make($data = Input::all(), Product::$rules);
if($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
$old_img = "";
if(isset($data['image']) and !empty($data['image']))
{
$image = Input::file('image');
$filename = time().'-'.$image->getClientOriginalName();
Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products/'.$filename);
$data['image'] = 'img/products/'.$filename;
$old_img = $product->image;
}
$product->update($data);
File::delete('public/'.$old_img);
return Redirect::route('admin.products');
}
Ensure that your form is a multipart one by adding
'files' => 'true'
to the config array.
first add this to your form tag enctype="multipart/form-data"
second in your validation just 'file'=>'required|mimes:jpeg,png,jpg,gif,svg'
validate mimes and remove image

Output post for second wordpress editor

I recently added a new editor to all my pages and posts admin area with the Wordpress 3.3 new feature to do this
add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
// get and set $content somehow...
wp_editor( $content, 'mysecondeditor' );
}
My question is how do I output what I enter in this second editor on my website/page? Do I need to make a custom loop? The codex is not very helpful unfortunately.
Thanks
You'll need get_post_meta(), use it like:
echo get_post_meta(get_the_id(), 'mysecondeditor');
Read more: http://codex.wordpress.org/Function_Reference/get_post_meta
To save the data entered in your second editor you'll need this code in your functions.php file:
add_action( 'save_post', 'save_post', 10, 2 );
function save_post( $post_id, $post ) {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
update_post_meta( $post_id, 'mysecondeditor', stripslashes( $_POST['mysecondeditor'] ) );
}
So after that he's the full code for your second editor:
wp_editor( get_post_meta(get_the_id(), 'mysecondeditor', true), 'mysecondeditor' );
The true above makes sure only a single variable is returned and not an array so you can use it right away.
user2019515I's (Apr 18 '13 at 12:06) answer works for me, I can add text and gallery, but when I display that with this code:
<?php echo get_post_meta(get_the_ID(),'mysecondeditor')['0']; ?>
I got gallery code instead of the images, so:
mytext [gallery ids="102,62"]
How could I display the text (mytext) and the images too?

I can't make 100x120 thumbnail in Wordpress

I need to make three thumbnails for one Wordpress template:
678x301 px
271x120 px
100x120 px
So I have put these on functions.php:
<?php add_theme_support( 'post-thumbnails' );
add_image_size( 'index-thumb', 271, 120, true );
add_image_size( 'featured', 678, 301, true );
add_image_size( 'sieme', 100, 120, true );
?>
But unfortunately, the third one doesn't work. When I use this, it doesn't link to foo_100x120.jpg (which exists, I've checked manually), but to foo.jpg and set width and height by HTML. Here is the screen with single post view, where I've put three thumbnails for the test. HTML is below, in Firebug:
http://i.stack.imgur.com/MCTM8.png
Here is the part of single.php:
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'featured' );
the_post_thumbnail( 'index-thumb' );
the_post_thumbnail( 'sieme' );
}
?>
I don't know, why it happens.
If the images already exist, you'll need to use the Regenerate Thumbnails Plug-in. After you've ran it once any uploaded images should be cropped as expected.