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.
Related
I just want some clarification and advice regarding this tag in WordPress.
This tag is showing in my WordPress head even I'm not using Gutenberg.
link rel="stylesheet" id="wp-block-library-css"
Is this necessary or required?
Do I need to remove this to improve page speed?
Is there any effect if I remove this tag?
Please enlighten me.
Thank you
I use to remove this stylesheet on websites which are not using Gutenberg.
I don't think there is other effect than removing this stylesheet, you can do it safely.
To go a bit further, you can remove it only for some post types like
function remove_wp_block_library_css() {
if( !is_singular('post') ) {
wp_dequeue_style( 'wp-block-library' );
}
}
add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css' );
If you are not using Gutenberg at all, you can unload styles further more like this :
// Unload Gutenberg-related stylesheets.
add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
function remove_block_css() {
wp_dequeue_style( 'wp-block-library' ); // Wordpress core
wp_dequeue_style( 'wp-block-library-theme' ); // Wordpress core
wp_dequeue_style( 'wc-block-style' ); // WooCommerce
wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront theme
}
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 );
}
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
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 am using CakePHP 2.x with tcpdf to create a PDF file. I want to output it now to the browser, without saving.
Layout->pdf.ctp
<?php
header("Content-type: application/pdf");
echo $content_for_layout;
?>
View->pdf_testing.ctp
<?php
App::import('Vendor', 'xtcpdf');
$pdf = new XTCPDF('P', 'mm', 'USLETTER', true, 'UTF-8', false);
$textfont = 'freesans'; // looks better, finer, and more condensed than 'dejavusans'
$pdf->AddPage();
$pdf->setHeaderData('', '', '', 'RMA#100000');
$pdf->SetTitle('Some Text');
$pdf->SetHeaderMargin(20);
$pdf->SetTopMargin(40);
$pdf->setFooterMargin(20);
$pdf->SetAutoPageBreak(True, PDF_MARGIN_FOOTER);
$pdf->SetAuthor('Any Author');
$pdf->SetDisplayMode('real', 'default');
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($textfont, 'B', 20);
$pdf->Cell(0, 14, "TESTING", 0, 1, 'L');
echo $pdf->Output('filename.pdf', 'I');
?>
For Internet Explorer this works fine and the PDF shows up.
With Chrome i get only very userfriendly output like:
%PDF-1.7 %���� 10 0 obj << /Type /Page /Parent 1 0 R /Las....
Even when i set it to
echo $pdf->Output('filename.pdf', 'F');
to save it as file i still get a "Content Length:20" and, with option "I" for Inline, i always get Content-Type HTML/Text instead of Application/pdf.
Any ideas are very appreciated.
Thanks in advance.
Rather than including the header call in your layout file, try adding the following code to your controller method:
$this->response->type('application/pdf');
Cake sends out headers when it's ready so you shouldn't include them directly in your view/layout files. If you want to set a header you should use the response's header method, for example:
$this->response->header('Location', 'http://example.com');
I'm not sure if this will fix your problem as I can't test it, but I think it has a good shot.
I have same issue and fixed it by disabling auto render in cakephp controller method:
$this->autoRender = false;