2012-09-13 64 views
0

我想在我的模板鏈接到第一個子頁面(這是一個部分概述頁面,所以總會有子頁面可用)。該鏈接將始終具有相同的文本。Typoscript:如何獲取當前頁面的第一個子頁面的ID?

如何獲取第一個子頁面的ID?

pagelink = TEXT 
pagelink { 
    value = Link to first child page 
    typolink { 
     parameter = [[id of first child page]] 
    } 
} 

回答

1

這裏有一個簡單的解決方案:

pagelink = HMENU 
pagelink { 
    # only display if there is a subpage 
    stdWrap.required = 1 
    # with value directory, the default special.value is the current page id 
    special = directory 
    # limit to 1 page 
    maxItems = 1 
    # link item 
    1 = TMENU 
    1 { 
     NO = 1 
    } 
} 

要覆蓋網頁的標題,用這個:

pageLink = HMENU 
pageLink { 
    # only display if there is a subpage 
    stdWrap.required = 1 
    # with value directory, the default special.value is the current page id 
    special = directory 
    # limit to 1 page 
    maxItems = 1 
    # link item 
    1 = TMENU 
    1 { 
     NO = 1 
     NO { 
      doNotLinkIt = 1 
      stdWrap.cObject = TEXT 
      stdWrap.cObject { 
       typolink.parameter.field = uid 
       # override text of menu item 
       value = Dummy Text 
      } 
     } 
    } 
} 
+0

好的,謝謝。給我正確的鏈接。你能告訴我如何替換菜單項中的頁面標題嗎?或者我必須用CSS隱藏它並使用換行來顯示我需要的文本? – Tim

+0

@Tim是的,我把它添加到我的文章。 – Shufla

0

有幾種方法可以做到這一點(例如,使用HMENU),但我會去爲這一個,因爲它是明確和容易,如果你一旦決定,使之更加複雜的修改(比如在頁面標題某處文本鏈接,基於媒體字段渲染縮略圖)。

pagelink = CONTENT 
pagelink { 
    table = pages 
    select { 
    pidInList = this 
    orderBy = sorting ASC 
    max = 1 
    } 
    renderObj = TEXT 
    renderObj { 
    value = Link to first child page 
    typolink { 
     parameter.field = uid 
    } 
    } 
} 

注意

  • 要在頁面標題作爲文本鏈接,取代value = Link to first child pagefield = title
  • 它只會是概述頁面上顯示正確的鏈接,而不是它的子頁面。要在子頁面上顯示,必須採取不同的方法。
+0

我不建議這樣做,因爲無效的類型的頁面(系統夾,間隔)也可以鏈接。還會顯示設置了「在菜單中隱藏」的頁面。 – Shufla

+0

@Shufla謝謝你的提示。也許我可以在'select'中添加'where'子句來過濾掉隱藏的頁面......'where = doktype = 1 AND hidden = 0' – Tim

+0

@Tim當然你可以這樣做,但是還有更多值尊重。 HMENU爲你做了這一切。 – Shufla

相關問題