1

3 つの異なるコンテンツ タイプからタイトルを取得するビューがあります。これらのコンテンツ タイプの 1 つには、外部 Web サイトにリンクするタイトルがあり、他の 2 つのタイプには、Drupal サイト内のノードにリンクするタイトルがあります。タイトルのコンテンツ タイプに応じてリンクを異なる方法で処理するように [タイトル] フィールドを設定する方法はありますか?

以下のVladに感謝します!! :)

views-view-fields--news--block.tpl.phpこれは、テンプレートで使用している作業コードです..

<?php if ($fields['type']->content == 'Event'): ?>
  <a href="<?php print $fields['path']->content; ?>"><?php print $fields['title']->content; ?></a>
<?php endif; ?>

<?php if ($fields['type']->content == 'PATF News'): ?>
  <a href="<?php print $fields['path']->content; ?>"><?php print $fields['title']->content; ?></a>
<?php endif; ?>

<?php if ($fields['type']->content == 'News Link'): ?>
//This link goes to _blank
 <a href="<?php print $fields['field_link']->content; ?>" target="_blank"><?php print $fields['title']->content; ?></a>
<?php endif; ?>
4

2 に答える 2

1

Drupal6

  1. ビュー設定で、に追加Node: TypeしますFields
  2. Basic settingsグループでクリックしTheme: InformationてクリックRow style output
  3. からすべてのコンテンツをテーマ フォルダー内のテーマ ファイル (またはRow style outputのような名前にする必要があります) にコピーします。views-view-fields--viewsname.tpl.phpviews-view-fields--viewsname--viewsnamw.tpl.php
  4. コンテンツ タイプを確認する必要がある出力を変更し、別の出力を作成します。

Drupal 7

Theme: Informationグループで見つけることができる違いはかなり似ており、グループAdvancedに追加する必要がありContent: TypeますFields

views-view-fields--xxx--xxx.tpl.phpファイルに次のように記述します。

if ($fields['type']->content == 'Page') {
  // print title linking to node
  print $fields['title']->content;
}
if ($fields['type']->content == 'News') {
  // print title linking to other website
  print 'http://example.com/'. $fields['title']->content;
}

改善されたコード

$link = $fields['path']->content;
$title = $fields['title']->content;
$options = array();

if ($fields['type']->content == 'News Link') {
  $link = $fields['field_link']->content;
  $options['attributes']['target'] = '_blank';
}

print l($title, $link, $options);
于 2012-07-12T22:43:18.817 に答える
-1

私は以前に次の手順でこれを行いました:

  1. コンテンツ タイトルコンテンツ リンク、および外部リンクのフィールドを含めます。
  2. ビューからコンテンツ タイトルとコンテンツ リンクを非表示にします。
  3. コンテンツ リンクのリライト結果は、コンテンツ タイトルのトークンに設定する必要があります (どちらも非表示のままです)。
  4. 外部リンク フィールドの結果動作は、コンテンツ リンクのトークンに設定しないでください。

これにより、外部リンクが存在する場合は常に表示され、存在しない場合は元のコンテンツにリンクされたタイトルにフォールバックします。

于 2013-09-09T18:06:38.703 に答える