[SOLVED] mix post type in news page

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

[SOLVED] mix post type in news page

Post by giapippo »

hello to all
I have a news page that summarizes all the news site.
News are of 2 types with 2 different template
how can I bring up a page all news using their own template for each post summaries?

this is the website page

http://www.tabafactory.com/

some posts have pictures while others video

but with the tag {news}

I can not say use the template for video news category video
and use the template pictures for the news of the category photo
right?
or at least I do not know how to do it :-[

thanks for help
Last edited by giapippo on Tue Jun 02, 2015 10:08 am, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

If I understand you correctly you want to have a page with all news items, which are a mix of 'video' items and 'photo' items. Right?

You need to use one template and inside the template check whether it's a video item or a photo item.

Code: Select all

pseudo code for template (both summary and detail):
...
{if $entry->fields.YOUTUBEVIDEOID->value != ''}
  <!-- here the specific code for video items -->
{else}
  <!-- here the specific code for NON video items -->
{/if}
...
Obviously YOUTUBEVIDEOID should be replaced with an alias you use for the field definition containing the 'video input'.
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

like this summary template ?

Code: Select all

{if $entry->fields.youtube->value != ''}



{foreach from=$items item=entry}
<!-- blog-post -->
      <div class="blog-post video-post">
       <div class="inner-post">
        <!-- youtube -->
        <__iframe class="videoembed" src="http://www.youtube.com/embed/{$entry->fieldsbyname.youtube->value}"></__iframe>
        <!-- End youtube -->
        <div class="post-content">
   <a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
   <p> {if $entry->content}{eval var=$entry->content|truncate:200:"..."}{/if} </p>

        </div>
       </div>
      </div>

{/foreach}



{else}



{foreach from=$items item=entry}
 <!-- blog-post -->
      <div class="blog-post gallery-post">
       <div class="inner-post">
        <div class="flexslider">
         <ul class="slides">
          <li>
           <img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine1->value}" />
          </li>
          <li>
           <img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine2->value}" />
          </li>
<li>
           <img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine3->value}" />
          </li>
         </ul>
        </div>
        <div class="post-content">
         <a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
         <p>{if $entry->content} {eval var=$entry->content|truncate:200:"..."}{/if}
 </p>
       </div>       
       </div>
      </div>

{/if}


{/foreach}

but dont work :-\
nikkio
Forum Members
Forum Members
Posts: 63
Joined: Sun Jun 08, 2008 12:34 pm

Re: mix post type in news page

Post by nikkio »

I think you should put the if after the foreach..

Code: Select all

{foreach from=$items item=entry}
{if $entry->fields.$youtube->value != ""}
---youtube code
{else}
--- non youtube
{/if}
{/foreach}
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

thanks for help but i think dont work

http://www.tabafactory.com/

my mews summary template now is:

Code: Select all

{foreach from=$items item=entry}
{if $entry->fields.youtube->value != ''}

<!-- blog-post -->
						<div class="blog-post video-post">
							<div class="inner-post">
								<!-- youtube -->
								<__iframe class="videoembed" src="http://www.youtube.com/embed/{$entry->fieldsbyname.youtube->value}"></__iframe>
								<!-- End youtube -->
								<div class="post-content">
			<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
			<p> {if $entry->content}{eval var=$entry->content|truncate:200:"..."}{/if} </p>

								</div>
							</div>
						</div>





{else}

 <!-- blog-post -->
						<div class="blog-post gallery-post">
							<div class="inner-post">
								<div class="flexslider">
									<ul class="slides">
										<li>
											<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine1->value}" />
										</li>
										<li>
											<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine2->value}" />
										</li>
<li>
											<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine3->value}" />
										</li>
									</ul>
								</div>
								<div class="post-content">
									<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
									<p>{if $entry->content}	{eval var=$entry->content|truncate:200:"..."}{/if}
 </p>
							</div>							
							</div>
						</div>

{/if}


{/foreach}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

You have an error in the content/template where you call the {news} tag.

Further: seems you're working on an older version of cmsms.

Read the help of the news module (or a sample template). Could well be that the correct syntax is : $entry->fiedsbyname.youtube->value
Maybe both are ok.
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

ok now the site is not by mistake
but it continues to ignore the template summary of news
I tried setting it as the default
but nothing changes
definitely will be a trivial problem
again thanks for the help

new summary template :

Code: Select all

{foreach from=$items item=entry}
{if $entry->fiedsbyname.youtube->value != ""}

<!-- blog-post -->
					<div class="blog-post video-post">
						<div class="inner-post">
							<!-- youtube -->
							<__iframe class="videoembed" src="http://www.youtube.com/embed/{$entry->fieldsbyname.youtube->value}"></__iframe>
							<!-- End youtube -->
							<div class="post-content">
		<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
		<p> {if $entry->content}{eval var=$entry->content|truncate:200:"..."}{/if} </p>

							</div>
						</div>
					</div>





{else}

 <!-- blog-post -->
					<div class="blog-post gallery-post">
						<div class="inner-post">
							<div class="flexslider">
								<ul class="slides">
								<li>
									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine1->value}" />
									</li>
									<li>
									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine2->value}" />
									</li>
<li>									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine3->value}" />
									</li>
									</ul>
							</div>
							<div class="post-content">
							<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
						<p>{if $entry->content}	{eval var=$entry->content|truncate:200:"..."}{/if} </p>
							</div>							
							</div>
						</div>

{/if}

{/foreach}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

It's hard for us to troubleshoot the problem.

Create a new template and start with the basics:

For example.

Code: Select all

{foreach from=$items item=entry}
<pre>{$entry->fieldsbyname|print_r}</pre>
{if $entry->fiedsbyname.youtube->value != ""}
VIDEO!
{else}
PHOTO!
{/if}
{/foreach}
Try to understand what's happening and what properties you can check and use. etc. etc.
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

hallo thanks for help

http://www.tabafactory.com/

????

thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

Seems to work right?

This code can be removed, it's used to get some insight in available properties you can use:

Code: Select all

<pre>{$entry->fieldsbyname|print_r}</pre>
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

hello I think you understand what could be the problem.
if I reverse the position of the code so I get a reverse result.
whereas before it was always taken the template photo and completely discarded the video, is now being used more and discarded photos and videos

why?
thanks for the help

Code: Select all

{foreach from=$items item=entry}

{if $entry->fiedsbyname.immagine1->value != ""}


 <!-- blog-post -->
					<div class="blog-post gallery-post">
						<div class="inner-post">
							<div class="flexslider">
								<ul class="slides">
								<li>
									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine1->value}" />
									</li>
									<li>
									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine2->value}" />
									</li>
<li>									<img alt="{title}" src="{$entry->file_location}/{$entry->fieldsbyname.immagine3->value}" />
									</li>
									</ul>
							</div>
							<div class="post-content">
							<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
						<p>{if $entry->content}	{eval var=$entry->content|truncate:200:"..."}{/if} </p>
							</div>							
							</div>
						</div>


{else}

 <!-- blog-post -->
					<div class="blog-post video-post">
						<div class="inner-post">
							<!-- youtube -->
							<__iframe class="videoembed" src="http://www.youtube.com/embed/{$entry->fieldsbyname.youtube->value}"></__iframe>
							<!-- End youtube -->
							<div class="post-content">
		<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}"><h2>{$entry->title|cms_escape}</h2></a>
		<p> {if $entry->content}{eval var=$entry->content|truncate:200:"..."}{/if} </p>

							</div>
						</div>
					</div>



{/if}

{/foreach}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

The test should work. But note that even a single space in that field would make the test fail (space is not an empty string)
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

the system ignores one of the two template
or use the template VIDEO or use the template for all PHOTOS
and excludes always the first tempalte immediately after the string

Code: Select all

{if $entry->fiedsbyname.immagine1->value != ""}


I forgot
the post titled
"Heavy Sand - Creative Photography" in the home page

is a PHOTOS post but use the VIDEO template :-[
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: mix post type in news page

Post by velden »

I'm sorry. Just see this typo:

{if $entry->fieldsbyname.youtube->value != ""}
giapippo
Forum Members
Forum Members
Posts: 176
Joined: Tue Feb 28, 2012 1:24 pm

Re: mix post type in news page

Post by giapippo »

ahahahahahhahahaha

{if $entry->fieldsbyname.youtube->value != ""}

velden you are mythical !!
Locked

Return to “Modules/Add-Ons”