Page 1 of 1
Image fields for News article
Posted: Tue Feb 06, 2007 9:13 pm
by Dante
Hi There,
I am new to CMSMS but so far I am very impressed.
Is there a way I can have an image field and a thumbnail image field for each news article where a user can upload images to the cms (when inputting news article content)?
I would then like to retrieve these images somehow in the news templates so I can manipulate them using css.
I do not want the CMS user to have add the images and the html/css code using the WYSIWYG editor.
regards,
Dante
Re: Image fields for News article
Posted: Wed Feb 07, 2007 2:38 pm
by myshko
Hi Dante,
I'm looking for exactly the same thing. If I find anything I'll pass it along.
I might end up trying to add it myself, so if I have any luck I'll let you know.
Regards,
Mikey
Re: Image fields for News article [SOLVED]
Posted: Wed Feb 07, 2007 3:05 pm
by myshko
Okay,
Here is a simple workaround. It's doesn't involve a field but may suit your needs for the time being.
In your summary template, you can insert an html image tag and link it to a specific image file relating to your article using the 'title' tag, as below.
Code: Select all
<img src="uploads/images/newsImages/{$entry->title}.jpg" alt="{$entry->title}" />
This will then output an image with the same name as your articles 'title' field.
So if your news article is titled 'CMSMS THE CMS!' your image would be named 'CMSMS THE CMS!.jpg' with an alt tag the same.
The images must always be placed in the same folder, in my case 'uploads/images/newsImages/'.
Of course, the obvious downsides are:
- An image is always outputted. So if you don't want an image you'll have to upload a very small white jpeg, not great (especially if you have CSS borders!
- File format must always be the same
- If you change the title, you have to rename the image.
- It's abit annoying to have to name images specifically and put them in the right place.
But it may work ok for you. If I find a better way I'll add it to the post.
Any problems feel free to PM or email me.
M
Re: Image fields for News article [SOLVED]
Posted: Wed Feb 07, 2007 3:45 pm
by cyberman
under-radar wrote:
So if your news article is titled 'CMSMS THE CMS!' your image would be named 'CMSMS THE CMS!.jpg' with an alt tag the same.
Note: The whitespaces in filename can make trouble !
Re: Image fields for News article
Posted: Wed Feb 07, 2007 5:31 pm
by stopsatgreen
As each article has an id, you could use that instead;
Code: Select all
<img src="uploads/images/newsImages/image_{$entry->id}.jpg" alt="{$entry->title}" />
Not a perfect solution, but a workaround.
Re: Image fields for News article
Posted: Wed Feb 07, 2007 11:31 pm
by myshko
Thanks guys,
Thats a good point and a good workaround
Still would be better to simply have an image field... hmmmm
Mikey
Re: Image fields for News article
Posted: Fri Mar 16, 2007 3:58 pm
by Steppenwolf
Hi,
I found another solution which in my opinion is more comfortable and works
"as it should".
You can put the thumbnail image into the news summary and format it the way you want (for example right or left aligned). Then a
user defined tag extracts either the thumbnail or the rest of the summary.
How to:
Insert this user defined tag
NewsSummaryExtract:
$summary = $params['summary'];
$extract = $params['extract'];
if( preg_match( "/^(.*)(\]+\>)(.*)$/i", $summary, $matches ) == 1 )
{
switch( $extract )
{
case "image":
echo( $matches[2] ); break;
case "text":
default:
echo( $matches[1].$matches[3] ); break;
}
}
else if( $extract == "text" )
{
echo( $summary );
}
Then you can use the summary parts in your news summary template this way:
The thumbnail:
{NewsSummaryExtract extract="image" summary=$entry->summary}
The text (= the rest of the summary):
{NewsSummaryExtract extract="text" summary=$entry->summary}
Example of a news summary template:
{foreach from=$items item=entry}
{if $entry->summary}
link}">
{NewsSummaryExtract extract="image" summary=$entry->summary}
{/if}
{$entry->titlelink}
{if $entry->summary}
{NewsSummaryExtract extract="text" summary=$entry->summary}
{else if $entry->content}
{eval var=$entry->content}
{/if}
{/foreach}
Be careful not to overwrite your existing news summary template, this is only an example, which is not based on the default template.
Regards Eberhard
Re: Image fields for News article
Posted: Thu Jul 05, 2007 6:23 am
by sturla69
Brilliant function, but a word of warning. It will not work if your editor insert a -tag before the image. At least it won't for me. Switched from FCKEditor to TinyMCE, and it solved it.