drupal cck image_field and imagecache - drupal

I am having trouble getting imagecache to generate a thumbnail based on a preset I have created named 'thumbnail'. I have an cck image_field and a custom node view. The code I am using to output my images is:
<?php foreach($node->field_comm_gallery as $galleryItem) { ?>
<?php print theme('imagecache', 'thumbnail', $galleryItem['filepath'], $alt = '', ''); ?>
<?php } ?>
The output I get from the following is:
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_0.jpg"/>
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_2.jpg"/>
Everything looks correct but those files do not exist in that folder.
My question: Is the print theme(..) call supposed to generate the thumbnail on the fly when it is called, or is the thumbnail generated when a node is created/updated?
I am using the GD Image processer and receive no errors.

The node field value has within it the display value already generated. So using theme function is not needed. But the file should be created regardless. It looks like the problem is the permission to either Drupals temp folder or the files folder. Take a look at those in the files settings.

Thanks for the help. It actually turned out to be this bug (http://drupal.org/node/540486#comment-2356560)
I had to remove the & from the function parameters in imageapi.module
function imageapi_gd_image_resize(&$image, $width, $height)
No clue why, but it seems to break when using php 5.x

Related

taxonomy.php doesn't display images from "../image/" folder

i have some images loading in the header (header.php) from the location "../images/"
code is
<div class="header">
<img src="../images/headerimg.gif" alt=""/>
</div>
while the pages and custom post type load the image correctly from the location ..
the taxonomy.php doesn't load the image at all instead shows the cross sign which image is there but not loaded
plz help
In wordpress, you should never use such relative paths.
You should use one of the Built-in path functions , like get_template_directory_uri()
<?php echo get_template_directory_uri(); ?>/images/headerimg.gif">
or in the event you want to be included or ovverriden by child theme use get_stylesheet_directory_uri()
All this of course assumes that the images are in a sub-folder called images under the main theme folder. ( which is how it is supposed to be )
In case that the image is an Uploaded image , it should be referenced by the ID or the URL that is supplied from the upload . Even in the case you do not want to do so for some ( probably wrong ) reason , you should then also use wp functions like for example wp_upload_dir()

Page not found error once submit form in addons contact_directory using concrete5?

I have purchased add-ons module contact_directory using concrete5, now I have need to customize on my requirement.
so I have need to changed file packages\contact_directory\blocks\contact_directory\view.php, I have created test.php file in same directory where my view.php file, so my form tag is url('contact_directory/test')?>">
so please tell me where it's wrong?
Concrete5 utilizes a loose MVC architecture for blocks. What this means is that unlike "plain old" php sites where you have a file that gets run when a certain URL is visited, your block's controller is always called instead. But you can have different functions in the controller that respond to different url's, and in the C5 world these are called actions.
So in your block's view.php file, change your form tag to this:
<form method="post" action="<?php echo $this->action('test'); ?>">
Then in the controller.php file, make a new public function that has the name "action_" followed by what you passed into the form tag. In your example, that would be:
public function action_test() {
//do stuff here
}
Now you're going to run into an issue because Concrete5 blocks always render the "view.php" template (there is no easy way to tell it to use a "test.php" file instead, for example). The easiest solution here is to combine two templates into your view.php file with an "if" statement. For example:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php if ($controller->getTask() == 'test'): ?>
<!-- Put all of the code from your test.php file here -->
<?php else: ?>
<!-- Put all the code from your view.php file here -->
<?php endif; ?>
One thing to note -- if your block gets placed in the Page Defaults or in a Global Area (or Stack), then it's possible that the form action won't submit to the right place. I'm not sure about this though -- this was a problem I ran into back in version 5.4.2, but it may have been fixed since then.
PS - If you want to look at some sample code that utilizes this form handling stuff in C5 blocks, download my free Email List Signup addon ( http://www.concrete5.org/marketplace/addons/email-list-signup ).

how to assign image dynamically in wordpress post

I am developing one wordpress site. I have made one post in it. Now I want to assign image in that post. For this, I have uploaded one image in media and attach that image to my post.
but how can I assign that uploaded image in my post? do I need to give path manually? or I can give dynamic path so that even if I upload this site on server or change main folder name, path gets changed automatically..
any help will be appreciated..
thank you
You should consider using Post Thumbnails (also known as Featured Images) in your posts. To do this, all you need to do is add the following to your functions.php file:
add_theme_support('post-thumbnails');
This will add a control in your Post Editor to add an image by either Uploading it or setting the URL, effectively "attaching" your image to your post in the way your looking for. To display the image in your template:
<?php
if(have_posts()) : while(have_posts()) : the_post();
if(has_post_thumbnail())
echo '<div class="post_thumb">'.get_the_post_thumbnail().'</div>';
?>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
As for changing folder names, paths, etc. you need to be careful with that approach. Remember that you're giving a path to an asset. The server doesn't know what YOU want, only what your code is requesting. If you expect to be changing paths to your assets around quite a bit, then you can always forgo Post Thumbnails in favor of clever naming conventions. Something like this:
<?php
if(have_posts()) : while(have_posts()) : the_post();
$imgPath = get_bloginfo('stylesheet_directory').'/images/featured_'.$post->post_name.'.jpg';
?>
<div class="post_thumb"><img src="<?php echo $imgPath; ?>" /></div>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
This looks for an image in your Theme Directory's images folder that is named featured_{post_slug}.jpg
The benefits to this approach is that Wordpress will always know where your theme folder is, regardless of URL changes. As long as you have an images folder in your theme directory, Wordpress will know where to look.
The drawback is that this code specifically doesn't first check for the EXISTENCE of the image before displaying it, which could lead to broken images if they aren't named properly or don't exist at all. This approach also requires the use of one file extension
A last option for you is to consider using Custom Fields to define paths to images. The benefit is that this does not require you to actually upload images to your server. However, this approach is still the least dynamic out of all of your options, and will likely break if paths to assets are changed.
Use whichever tool you feel is best for the job. Hope this helps!

drupal_set_message not working on one specific template?

I have one specific template which drupal_set_message() does nothing on. The $messages are printed out in a header include which also exists on this template. I've triple checked that it's using the template I think it is, etc.
The only difference I can tell between this and any other page template I'm using is that this is a node-specific template. Specifically page-node-170.tpl.php.
Anyone have any ideas?
Make sure that the custom template (page-node-170.tpl.php) has the following lines somewhere visible:
<?php if ($show_messages && $messages): print $messages; endif; ?>
<?php print $help; ?>

Trying to understand custom fields in WordPress

I'm trying to make my single.php page show more details about each project/item in a portfolio, with multiple larger image files that will display with captions to the right of the project description.
I'm thinking the best way to approach this would be to use the 'featured image' for the thumbnail display on the homepage which seems to be working now, but I've been trying to figure out Custom Fields to use for my other images (image1, image2, image3). I can't figure it out.
I go to "Enter new" under Custom Fields from the admin screen, enter image1 for the name. What goes in the Value field? How do I get it to work? I know I need to add some code to my single.php page... but what? And when/where do I upload the images themselves?
Any help would be greatly appreciated! I'm a little dense in the PHP department...
Have look at your single.php file. You will find the following lines, one near the top, the other lower down.
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
...
...
<?php endwhile; // end of the loop. ?>
Anything between these two lines will be applied over and over, once per blog post that happens to be displayed by that template file. So you should put your magic between those lines.
What you put there will be a mix of HTML and PHP. For instance, you might use this line:
<img src="<?php echo get_post_meta($post->ID, 'image1', true) ?>"/>
which combines
<img src=""/>
with
<?php echo get_post_meta($post->ID, 'image1', true) ?>
The PHP line looks up whatever value you have entered for the custom field named 'image1'. If you look at the HTML I used, you will see that this value is being placed inside the 'src' attribute. In other words, the value associated with 'image1' should be the url of that image.
You can expand upon this basic idea, but that's where your own creativity will have to come in.
[Is this not a repeated question?]

Resources