Page 1 of 1

[Solved] - News Module + Image Change Variable ?

Posted: Thu Jan 15, 2015 8:24 pm
by welsfordvfd
I am trying to do something that i believe would be possible. I just dont know how i would write the logic to make it possible. What I am trying to do is change a picture on the homepage of our website based on if there is news in a specific category.

For example:
News Categories = General, Weather, Recall

If General has articles and weather and recall do not ---> No image

If Weather has an article ---> Show "weather alert" image

If recall has article ---> Show "recall alert" image.

(there will never be a weather + recall article at the same time)

Any Ideas?

Server information is:
----------------------------------------------

Cms Version: 1.11.11

Installed Modules:

CMSMailer: 5.2.2
CMSPrinting: 1.0.5
FileManager: 1.4.5
MenuManager: 1.8.6
ModuleManager: 1.5.8
News: 2.14.4
Search: 1.7.11
ThemeManager: 1.1.8
Album: 1.10.3
FormBuilder: 0.8
Captcha: 0.5.0
CGExtensions: 1.42.2
FrontEndUsers: 1.24.1
CustomContent: 1.10
TinyMCE: 2.9.12
CGSimpleSmarty: 1.7.4
Uploads: 1.18.4
ListIt2: 1.4.1
ListIt2utubes: 1.4.1
CGUserDirectory: 1.4.4
CGGoogleMaps: 2.4.7
Guestbook: 1.4_RC2
CGFeedback: 1.6.7
MicroTiny: 1.2.7
JQueryTools: 1.2.6
Products: 2.21

Config Information:

php_memory_limit:
process_whole_template:
max_upload_size: 20000000
url_rewriting: mod_rewrite
page_extension: .html
query_var: page
image_manipulation_prog: GD
auto_alias_content: true
locale:
default_encoding: utf-8
admin_encoding: utf-8
set_names: true

Php Information:

phpversion: 5.3.13
md5_function: On (True)
gd_version: 2
tempnam_function: On (True)
magic_quotes_runtime: Off (False)
E_STRICT: 0
E_DEPRECATED: 0
memory_limit: 128M
max_execution_time: 120
output_buffering: On
safe_mode: Off (False)
file_uploads: On (True)
post_max_size: 20M
upload_max_filesize: 20M
session_save_path: /home/users/web/b2870/ipg.welsfordvfd/cgi-bin/tmp (0755)
session_use_cookies: On (True)
xml_function: On (True)
xmlreader_class: On (True)

Server Information:

Server Api: cgi-fcgi
Server Db Type: MySQL (mysqli)
Server Db Version: 5.5.40
Server Db Grants: Found a "GRANT ALL" statement that appears to be suitable
Server Time Diff: No filesystem time difference found

----------------------------------------------

Re: News Module + Image Change Variable ?

Posted: Thu Jan 15, 2015 8:49 pm
by calguy1000
This is relatively simple. Assuming that
1. {news} is called in your page template, without any category filters.
2. {news} is called in your page template in the </__body> section but above where the alert image would be displayed.
3. You only have the three categories.

You will need your summary template to capture the first 'image url' from either 'recall' or 'alert' categories...

something like: (untested)
{$alert_image=''}
{$foreach $items as $entry}
{* grab the first image from any news article that is not in the general category *}
{if $alert_image == '' && $entry->category != 'General' && $entry->fields.image->value != ''}
{$alert_image=$entry->fields.image->value}
{/if}
{* the rest of your news summary template *}
{$foreach}

Then in your page template (again.... after {news} is called).
{if $alert_image != ''}
<img src="$alert_image" alt="alert"/>
{/if}

Re: News Module + Image Change Variable ?

Posted: Thu Jan 15, 2015 9:06 pm
by welsfordvfd
The news is called in my page <__body> as:

{News number='3' summarytemplate="1pagenews")

However, the image I am trying to change is above the news in the header (above the navigation).

Webpage: http://welsfordvfd.com/

Right now the image is just a transparent image (I manually change image). If you were to look in the page source to see where its located you would look for:

<a href="http://welsfordvfd.com/alerts.html"><img src="uploads/images/alerts/blank.png" alt="Weather" width="180" height="71" /></a></h1>

Re: News Module + Image Change Variable ?

Posted: Thu Jan 15, 2015 9:11 pm
by velden
I think that would be pretty simple:

Code: Select all

{news category='Weather' summarytemplate='countItems' assign='news_count'}
{if trim($news_count) > 0}
  WEATHER  <!-- here your image tag -->
{else}
  {news category='Recall' summarytemplate='countItems' assign='news_count'}
  {if trim($news_count) > 0}
    RECALL  <!-- here your image tag -->
  {/if}
{/if}
News summary template 'countItems'

Code: Select all

{$items|@count}
This template will only return the number of items.