I simply need to print out an image via php in Drupal 7. I already have 3 presets, thumnail, medium and large. Does anyone know the exact code I need to print these out as I cannot seem to work it out?
As far as I know, in Drupal 6 it was something like this:
<img src="<?php print 'sites/default/files/imagecache/**thumbnail**/' . $node->field_image_cache['0']['filepath']; ?>" />
I'd be very grateful for any help.
Use theme_image_formatter.
E.g.
print theme("image_formatter", array(
'image_style' => 'thumbnail',
'item' => array(
'uri' => 'sites/default/files/image.jpg',
'alt' => t(""),
'title' => t(""),
'attributes' => array(),
),
));
Related
(I am very new to php, so please forgive my blatant ignorance.)
My portfolio site theme uses this array to display realted images. Currently the theme crops those images to squares. 'images_proportion' => 'marceau_core_image_size_square',
I would like to be able to control the size and proportions of these. Any thoughts on how I might do this would be greatly apreciated.
<div id="qodef-portfolio-single-related-items">
<h4 class="qodef-m-title"><?php echo esc_html__('Related projects', 'marceau-core') ?></h4>
<?php
$params = apply_filters(
'marceau_core_filter_portfolio_single_related_posts_params',
array(
'custom_class' => 'qodef--no-bottom-space',
'columns' => '4',
'posts_per_page' => 4,
'additional_params' => 'id',
'post_ids' => $related_posts['items'],
'layout' => 'info-on-hover',
'hover_animation_info-on-hover' => 'roll-out',
'title_tag' => 'h5',
'behavior' => 'columns',
'images_proportion' => 'marceau_core_image_size_square',
'image_source' => 'featured',
)
);
echo MarceauCore_Portfolio_List_Shortcode::call_shortcode( $params );
?>
</div>
I tried replaceing 'marceau_core_image_size_square' with actual ratios, like '16:9'. And I tried adding height and width to the array, but these megar efforts had no effect.
I'm a beginner in writing PHP, but working on developing themes in WordPress.
I have no idea how to echo my style option within my front-page.php.
My meta.php:
$meta_style = array();
$meta_style['meta_style'] = array(
'dash_icon' => 'list-view',
'title' => __('Section Settings', 'fluent'),
'description' => __('These are general section settings.','fluent'),
'context' => 'normal',
'priority' => 'high',
'option_name' => 'meta_style',
'caps' => array(),
'fields' => array(
'style' => array(
//...
'type' => 'select',
'options' => array(//option value = option label
'value' => 'white',
'value2' => 'black'
),
'multiple' => false,//allow multiple values to be selected - default false
'placeholder' => 'white'//placeholder text for the element
),
),
);
My front-page.php (it's wrapped in a BUTTON just a see if the variable echoes):
<button>
<? if($meta = get_post_meta($post->ID)){ if($meta['style'] == true){ echo $meta['value']; } } ?>
</button>
Can anyone provide an additional examples on how to echo other types, such as 'type' => 'text'?
I dont know exactly what you want, but you should:
1 - See if you're echoing the right information
2 - Use var_dump()
In your first code example you have a variable $meta_style which is a map. It has one key, 'meta_style' that leads to a next map. Inside that inner map you have the keys 'dash_icon' and so on. So for example this should echo the string 'normal':
echo $meta_style['meta_style']['context'];
However, in your second example, you have a variable $meta which is also a map, having keys 'style' and 'value'. You could echo those with:
echo $meta['style'];
echo $meta['value'];
Based on your example, I have no idea what these should do or how they should be related, or what their meaning should be.
New to cakephp came across a scenario where I have to make a text and an image a link.
Fortunately it was successful, however I noticed that there is an underline on my link and I have to remove it, as you can see on the picture below + the code on how I made it like that:
Cakephp Code:
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express    '),
'http://example.com', array('escape' => false));
normally this would be easy just by adding:
style="text-decoration:none"
in the css, however since I'm new to cake I am not aware of the syntax on how I can put an id or class that I can use for css, or in what I prefer, directly adding the style="text-decoration:none" in the array.I tried this one but it didn't work.
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express    '),
'http://example.com', array('escape' => false,'style'=>'text-decoration:none'));
How can I solve this? Any help is appreciated
This may help
echo $this->Html->link(
$this->Html->image('img/f.png', array('height' => '40', 'width' => '40'))
. '' . ('forensics express    '),
'http://example.com', array('escape' => false,'class'=>'no-decoration'));
In the stylesheet, you can create this class
.no-decoration{
text-decoratino:none;
}
You can use this as reference link : How to call CSS class on a CakePHP Html->link?
Just set it in your css (stylesheet) like this, instead of inline code.
a {text-decoration:none;}
I am using CakePHP and the FormHelper to generate my form.
However, I need to create a markup similar to the following structure:
(radio1) [TEXT_INPUT] or more credits
(radio2) No Limit
Now, I am not sure how to approach this, but logically I would imagine it to be something like:
$options = array(
'oneormore' => $this->Form->input( 'text_for_oneormore' ) . ' or more credits',
'nolimit' => 'No Limit'
);
echo $this->Html->radio( 'quantity', $options, array() );
Does anyone have any ideas they can offer? I am stumped on this issue.
One way would be to use the 'before' and 'after' options which append the string you put in there. I think you can get away with entire fields there.
http://book.cakephp.org/view/1393/options-before-options-between-options-separator-a
Another way would be to make your own helper based on the FormHelper.
I may be a bit late to the show, but I came across this issue in upgrading a site to cakephp 2.x. I found if I use the "'hiddenField' => false" option, I was able the separate the radio buttons and put text or select inputs between them:
Your question relates to which of the following:<br>
<?php
echo $this->Form->radio("qOption", array('0' => 'Find a store'), array("label" => false, 'hiddenField' => false));
echo $this->Form->radio("qOption", array('2' => 'Choose a Product'), array("label" => false, 'hiddenField' => false));
echo $this->Form->select('product', $products, array());
echo $this->Form->radio("qOption", array('1' => 'Other'), array("label" => false, 'hiddenField' => false));
echo $this->Form->input("other", array("class"=>"f_12_darkgray", "size"=>"40", 'div' => false, "label" => false));
?>
This seems like it should be simple, but I'm new to CakePHP. Maybe it's just something I should write in good ole HTML, but - was hoping to find out how do to this with CakePHP's HTML helper.
I just want an image link that has target="_blank".
This is what I tried:
<?php echo $this->Html->link($this->Html->image('tmp/728x90.jpg',
array('alt'=>'advertisement', 'height'=>'90',
'width'=>'728')),'http://www.google.com', array('target'=>'_blank')); ?>
(all in one line - just broke up for ease of viewing)
But when I do this, I get this:
<img src="/img/tmp/728x90.jpg" alt="advertisement" height="90" width="728" />
Any help is greatly appreciated.
Answer (thanks deceze)
<?php
$image = $this->Html->image(
'tmp/300x600.jpg',
array(
'alt'=>'advertisement',
'height'=>'600',
'width'=>'300'
)
);
echo $this->Html->link(
$image,
'http://www.google.com',
array(
'target'=>'_blank',
'escape' => false
)
); ?>
<?php echo $this->Html->link($this->Html->image('fb2.jpg',array('alt'=>'facebook', 'height'=>'90','width'=>'728')),'http://www.facebook.com', array('target'=>'_blank','escape'=>false)); ?>
You need to tell HtmlHelper::link not to HTML escape the input.
This is all very well documented in the manual.
The exact code will be like this
<?php
echo $this->Html->link(
$this->Html->image('tmp/728x90.jpg',
array(
'alt'=>'advertisement', 'height'=>'90',
'width'=>'728')
),
'http://www.google.com',
array(
'target'=>'_blank',
'escape'=>false)
);
?>
You need to use the Html->image . Check it out:
http://book.cakephp.org/view/1441/image
Like mentioned in the Cook Book, you can use the 'url' option of the image method:
echo $this->Html->image("recipes/6.jpg", array(
'alt' => "Brownies",
'url' => array('controller' => 'recipes', 'action' => 'view', 6)
));
echo $html->link("more",array('controller' => 'users', 'action' => 'index/welcome'), array('style'=>'_blank'), false, false);?> image('more-arrow.png', array('alt' => 'more','height'=>'11','width'=>'17'))?>