Learn about the top 2016 CMS trends. Read on.


Today and next week, we’ll cover the how to do of last week’s 10 ways of tt_news.

SavvyMiss.com Topical news Articles

SavvyMiss.com, a community for women, has lots of very topical content and for each topic, it’s best served within its own section. Additionally, as each topic has its own section, there’s also branded landing pages for each topic which allows for very targeted advertising.

SavvyMiss.com topical news articles

How-to Topical news Articles

The basic premise is to create not one, but multiple tt_news content elements each with only a specific category allowed.

tt_news General Settings

To prevent having to set the order by field and sorting direction in every tt_news content element, you can add the following to your TypoScript setup.

plugin.tt_news.listOrderBy = datetime DESC

On look and feel, you can assign a specific template for each tt_news content element.

tt_news Template

To limit the number of news items or even pick a specific page to send the reader to, you can change Other Settings.

tt_news Other Settings

AINonline.com most recent news listing

AINonline.com provides the latest news and conference information for the aviation industry. For them, getting the latest news in a teaser format is fairly common. However, they also have a second version of more recent news from specific industry sectors.

AINonline.com most recent news listing

How-to most recent news listing

This particular view is really a near default usage of a tt_news content element. The main issue is to decide whether the LIST or LATEST view is better suited to your needs. If you need to revise the template, you can select another like in above.

tt_news general settings latest

BJTonline.com news Articles in the menu

BJTonline.com is written for the users of business aircraft, as in those riding in the cabin. In the aim of getting the news where the readers are looking, the latest news articles are also linked from within the left navigation of the website.

BJTonline.com news articles in the menu

How-to news Articles in the menu

Due to very specific, non-generalized client needs, this particular menu change was handled by writing a non-public, custom extension which generates the entire left navigation.

tt_news Articles in Navigation

In another project, we created the left navigation to be created by TYPO3 as normal, but in certain cases, to call a user function from within the TMENU object.

The following PHP script, fileadmin/class.user_CustomMenu.php, is for class user_CustomMenu. Do be warned that this is an older script and may not play nicely with list paging.

<?php
class user_CustomMenu extends tx_ttnews {
	var $cObj;        // Reference to the parent (calling) cObj set  from TypoScript
	var $cObjOrg;        // Reference to the parent (calling) cObj  set from TypoScript
	// Default plugin variables:
	var $prefixId = 'tx_ttnews'; // Same as class name
	var $extKey = 'tt_news'; // The extension key.
	var $debugmpf = 0;

	function LoadTTNewsPlugin($pid) {
		// get the tt_contents which lists TT_NEWS ( list_type=9 )
		$result = @$GLOBALS['TYPO3_DB']->exec_SELECTquery( '*', 'tt_content', 'pid='. intval($pid) . ' AND CType='list' AND list_type=9 ' .  $this->cObj->enableFields('tt_content') );

		while ( $result != null &amp;&amp; $contentrow = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc( $result ) ) {
			unset($this->cObj->data );
			$this->cObj->data = $contentrow ;

			// convert flexform XML into array
			$this->pi_initPIflexForm();

			// check if it is a list or latest plugin
			$code = $this->pi_getFFvalue($this->cObj->data ['pi_flexform'], 'what_to_display', 'sDEF');

			if ( strpos($code, 'LIST' )  === 0 ||   strpos($code,  'LIST' ) > 0 ) {
				$this->theCode = $code;
				break;
			} else {
				$this->cObj->data = NULL;
			}
		}
	}

	/**
	 * Return value from somewhere inside a FlexForm structure
	 *
	 * @param    array        FlexForm data
	 * @param    string        Field name to extract. Can be given like 'test/el/2/test/el/field_templateObject' where each part will dig a  level deeper in the FlexForm data.
	 * @param    string        Sheet pointer, eg. 'sDEF'
	 * @param    string        Language pointer, eg. 'lDEF'
	 * @param    string        Value pointer, eg. 'vDEF'
	 * @return    string        The content.
	 */
	function pi_setFFvalue(&amp;$T3FlexForm_array,$fieldName,$newvalue, $sheet='sDEF',$lang='lDEF',$value='vDEF')    {
		$sheetArray = is_array($T3FlexForm_array) ?  $T3FlexForm_array['data'][$sheet][$lang] : '';

		if (is_array($sheetArray))    {
			$T3FlexForm_array['data'][$sheet][$lang][$fieldName][$value] = $newvalue;
		}
	}

	function GetMostPopularNewsArticlesMenuTop($I,$conf) {
		$this->conf = $conf;

		if (  $I['uid'] == $GLOBALS['TSFE']->page['pid'] ) {
			$this->cObjOrg = $this->cObj;

			$this->LoadTTNewsPlugin($GLOBALS['TSFE']->page['pid'] );

			if (  $this->cObj->data != NULL ) {
				$this->local_cObj = t3lib_div::makeInstance ('tslib_cObj'); // Local cObj.
				$this->debugmpf = 1;

				$this->pi_setFFvalue($this->cObj->data['pi_flexform'], 'listLimit', '8', 's_misc') ;

				if ( $this->conf['templateFile'] != '' &amp;&amp; $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 's_template') != ''  ) {
					$this->pi_setFFvalue($this->cObj->data['pi_flexform'], 'template_file',  NULL,  's_template');
				}

				$this->init($conf);
				unset($this->piVars['page'] );

				$content = $this->displayList();
				$this->debugmpf = 0;

				$link = '<li><i>'.$this->pi_linkToPage('More in '. $I ['title'], $I['uid'] ). '</i></li>';
				$I['parts']['after'] = '<ul><ul>'. $content.$link.'</ul></ul>';
			}
		}

		return $I;
	}

	function GetMostPopularNewsArticlesMenu($I,$conf) {
		$this->conf = $conf;

		if (  $I['uid'] == $GLOBALS['TSFE']->page['pid'] ) {
			$this->cObjOrg = $this->cObj;
			$this->LoadTTNewsPlugin($GLOBALS['TSFE']->page['pid'] );

			if (  $this->cObj->data != NULL ) {
				$this->local_cObj = t3lib_div::makeInstance('tslib_cObj'); // Local cObj.
				$this->debugmpf = 1;

				$this->pi_setFFvalue($this->cObj->data['pi_flexform'], 'listLimit', '8', 's_misc') ;

				if ( $this->conf['templateFile'] != '' &amp;&amp; $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 's_template') != ''  ) {
					$this->pi_setFFvalue($this->cObj->data['pi_flexform'],
							'template_file',  NULL,  's_template');
				}

				$this->init($conf);
				unset($this->piVars['page'] );

				$content = $this->displayList();
				$this->debugmpf = 0;

				$link = '<li><i>'.$this->pi_linkToPage('More in '. $I['title'], $I['uid'] ). '</i></li>';
				$I['parts']['after'] = '<ul>'. $content.$link.'</ul>';
			}
		}
		return $I;
	}
}
?>

The following TypoScript is what calls the above PHP script.

## Left Menu ( liv.leftMenu )
includeLibs.leftMenu = fileadmin/class.user_CustomMenu.php
lib.leftMenu = HMENU
lib.leftMenu {
	wrap = <ul>|</ul>
	excludeUidList =  314,315,316,317,318,319,320,321,322,323,324,325,352,353,354
	1 = TMENU
	1.expAll = 1
	1.NO{
		wrapItemAndSub = |*|<li>|<hr  class="white" /></li>|*|<li>|</li>
		stdWrap.case = upper
	}

	2 = TMENU
	2.wrap = <ul>|</ul>
	2.expAll = 1
	2.IProcFunc= user_CustomMenu->GetMostPopularNewsArticlesMenu
	2.IProcFunc.templateFile = fileadmin/templates/tt_news_leftmenu_template.htm

	2.NO{
		wrapItemAndSub = <li>|</li>
	}

	3 = TMENU
	3.wrap = <ul>|</ul>
	3.NO{
		wrapItemAndSub = <li>|</li>
	}
}


[PIDinRootline = 81]
	lib.leftMenu.1.IProcFunc= user_CustomMenu->GetMostPopularNewsArticlesMenuTop
	lib.leftMenu.1.IProcFunc.templateFile = fileadmin/templates/tt_news_leftmenu_template.htm
[global]

BJTonline.com paged news

BJTonline.com is the online home to the slick print magazine, as such advertisers are provided for plenty of views as well by paging the news articles after every 300 words. For longer articles, this might mean 7-times more ad views than normal.

BJTonline.com paged news

How-to paged news

For paging a news article, the directions provided by tt_news documentation on SINGLE view is on target. In essence, if you’re using the default tt_news template, you only need to add and adjust the following TypoScript in the setup area to your site.

plugin.tt_news {
	useMultiPageSingleView = 1
	maxWordsInSingleView = 300

	# insert pagebreaks only after paragraphs
	useParagraphAsPagebreak = 1

	# token used in news bodytext to trigger a pagebreak
	pageBreakToken = <---newpage--->

	# show subheader on all pages
	subheaderOnAllSViewPages = 0

	# append the pagebrowser to the bodytext without the special template marker ###NEWS_SINGLE_PAGEBROWSER###
	appendSViewPBtoContent = 0
}

BPMinstitute.org White Papers login or visitor registration

BPMinstitute.org was established in response to the demand for education and peer exchange on all aspects surrounding business process computing. As the website content provided is high-quality and at times sponsor-backed, there’s a strong need to prevent illegitimate access. To overcome this there’s membership access restrictions in place that’s also supplemented with the ability for website visitors to gain temporary access to a single white paper.

BPMinstitute.org White Papers login or visitor registration

How-to News Article login or User registration

When you have restricted access news content, you still want to give a means to show teasers for, yet not give away your content. Most of the time, it’s a case of a show all or nothing. With TYPO3’s tt_news, with multiple tt_news content elements that manipulate the Access and Template properties, you can create access level views.

As you can see below, creating these limited and full news view does take a little preparatory work on tt_news content elements, login content element and a registration content element.

tt_news Access Restrictions

When dealing with the member registration aspects, a bit of custom coding was required for this originally TYPO3 3.6 website. These days those, you can use extension sr_feuser_register quite normally. The hard part is the need to enable auto-login after registration back to the current page.

Got Questions?

Please share them by commenting on this blog post.
From May 11, 2009

Still stuck? Write us.

  • jack .

    how to change format of date and time in tt_news(typo3).

    • I’m sorry for the delay, not sure how I missed your question. In your constants sections you can add something like the following.

      `
      plugin.tt_news {
      displaySingle {
      # cat=cbstarter.tt_news; type=string; label=Single News Date Format
      date_stdWrap.strftime = %A, %B %e, %Y
      # cat=cbstarter.tt_news; type=string; label=Single News Time Format
      time_stdWrap.strftime = %l:%M %p %Z
      }

      displayLatest {
      # cat=cbstarter.tt_news; type=string; label=Latest News Date Format
      date_stdWrap.strftime = %B %e, %Y
      # cat=cbstarter.tt_news; type=string; label=Latest News Time Format
      time_stdWrap.strftime = %l:%M %p %Z
      # cat=cbstarter.tt_news; type=string; label=Latest Subheader Crop: Number of characters, break characters replacement, break at whole words only
      subheader_stdWrap.crop = 300 | … | 1
      }

      displayList {
      # cat=cbstarter.tt_news; type=string; label=List News Date Format
      date_stdWrap.strftime = %B %e, %Y
      # cat=cbstarter.tt_news; type=string; label=List News Time Format
      time_stdWrap.strftime = %l:%M %p %Z
      # cat=cbstarter.tt_news; type=string; label=List Subheader Crop: Number of characters, break characters replacement, break at whole words only
      subheader_stdWrap.crop = 300 | … | 1
      }

      displayRelated {
      # cat=cbstarter.tt_news; type=string; label=Related News Date & Time Format
      strftime = %B %e, %Y %l:%M %p
      }
      }
      `

  • how can be setup tt_news to have at on clickon on a category title, subcategory expanded .
    In default setup , first is needed to click on a category and after need to click on + to expand subcategory

    • Mirela, Thank you for writing. Are you using the default tt_news template for the category listing? If so, you’ll need to use a custom template instead that’ll integrate some JavaScript to give the actions you desire. I don’t have code handy to do so right off hand, but jQuery and checking out similar solutions in this case will be your best bet research and experimentation wise.