Ho trovato in rete un interessante post su come gestire la visualizzazione del titolo in una pagina usando cck.
L'indirizzo del post è il seguente:
http://addoa.com/blog/how-make-optionally-hide-node-titles-drupal-using-cck
Il problema è che a me non funziona e non capisco perchè.
Ho pesonalizzato il contenuto "page" inserendo il nuovo campo ed adesso ho il check-box per nascondere il titolo ma anche spuntandolo non ho effetti sul titolo.
Nel post si legge di pesonalizzare il page.tpl.php nel seguente modo:
Step 8 — Find the PHP code that displays the page's title
Locate the PHP code that displays the title:
<?php
print $title;
?>
It may be surrounded by additional related HTML and PHP that define layout, styles, or in which cases the title should load:
<?php if ($title): ?>
<div id="title"><h1><?php print $title; ?></h1></div>
<?php endif; ?>
Step 9 — Insert your title hide field as a class of the title's H1 tag
Insert your title hide field as a class of the H1 tag. This will look something like this (with the addition in bold):
<?php if ($title): ?>
<div id="title"><h1 class="title <?php if(!empty($node->field_titlehide[0]['value'])) {$titlehide = $node->field_titlehide[0]['value']; print $titlehide;} ?>"><?php print $title; ?></h1></div>
<?php endif; ?>
Step 10 — Finito
ma nonostante i cambiamenti il titolo non scompare..........
Io uso come tema un genesis personalizzato, qualcuno sa consigliarmi sul da fare
TKS PGF
codice del mio page.tpl.php:
<?php
// $Id: page.tpl.php,v 1.1.2.19 2009/06/12 15:44:26 jmburnz Exp $
/**
* @file page.tpl.php
* Theme implementation to display a single Drupal page for Genesis Subtheme.
*
* Available variables:
*
* General utility variables:
* - $base_path: The base URL path of the Drupal installation. At the very
* least, this will always default to /.
* - $css: An array of CSS files for the current page.
* - $directory: The directory the theme is located in, e.g. themes/garland or
* themes/garland/minelli.
* - $is_front: TRUE if the current page is the front page. Used to toggle the mission statement.
* - $logged_in: TRUE if the user is registered and signed in.
* - $is_admin: TRUE if the user has permission to access administration pages.
*
* Page metadata:
* - $language: (object) The language the site is being displayed in.
* $language->language contains its textual representation.
* $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
* - $head: Markup for the HEAD section (including meta tags, keyword tags, and
* so on).
* - $head_title: A modified version of the page title, for use in the TITLE tag.
* - $styles: Style tags necessary to import all CSS files for the page.
* - $scripts: Script tags necessary to load the JavaScript files and settings
* for the page.
* - $section_class: A CSS class that uses .section + the 1st URL argument, allows for
* themeing site sections based on path.
* - $classes: A set of CSS classes (preprocess $body_classes + Genesis custom classes).
* This contains flags indicating the current layout (multiple columns, single column),
* the current path, whether the user is logged in, and so on.
*
* Site identity:
* - $front_page: The URL of the front page. Use this instead of $base_path,
* when linking to the front page. This includes the language domain or prefix.
* - $site_logo: The preprocessed $logo varaible. Includes the path to the logo image,
* as defined in theme configuration and wrapped in an anchor linking to the homepage.
* - $site_name: The name of the site (preprocessed) wrapped in an anchor linking to the homepage.
* Empty when display has been disabled in theme settings.
* - $site_slogan: The slogan of the site, empty when display has been disabled
* in theme settings.
* - $mission: The text of the site mission, empty when display has been disabled
* in theme settings.
*
* Navigation:
* - $primary_menu: The preprocessed $primary_links (array), an array containing primary
* navigation links for the site, if they have been configured.
* - $secondary_menu: The preprocessed $secondary_links (array), an array containing secondary
* navigation links for the site, if they have been configured.
* - $search_box: HTML to display the search box, empty if search has been disabled.
*
* Page content (in order of occurrance in the default page.tpl.php):
* - $leaderboard: Custom region for displaying content at the top of the page, useful
* for displaying a banner.
* - $header: The header blocks region for display content in the header.
* - $secondary_content: Full width custom region for displaying content between the header
* and the main content columns.
* - $breadcrumb: The breadcrumb trail for the current page.
* - $content_top: A custom region for displaying content above the main content.
* - $title: The page title, for use in the actual HTML content.
* - $help: Dynamic help text, mostly for admin pages.
* - $messages: HTML for status and error messages. Should be displayed prominently.
* - $tabs: Tabs linking to any sub-pages beneath the current page (e.g., the view
* and edit tabs when displaying a node).
* - $content: The main content of the current Drupal page.
* - $content_bottom: A custom region for displaying content above the main content.
* - $left: Region for the left sidebar.
* - $right: Region for the right sidebar.
* - $tertiary_content: Full width custom region for displaying content between main content
* columns and the footer.
*
* Footer/closing data:
* - $footer : The footer region.
* - $footer_message: The footer message as defined in the admin settings.
* - $feed_icons: A string of all feed icons for the current page.
* - $closure: Final closing markup from any modules that have altered the page.
* This variable should always be output last, after all other dynamic content.
*
* @see template_preprocess()
* @see template_preprocess_page()
* @see genesis_preprocess_page()
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
<?php print $head; ?>
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/formattafont.css" />
<link type="text/css" rel="stylesheet" media="print" href="/sites/all/themes/genesis_miotema/css/print.css" />
</head>
<?php
/**
* Change the body id selector to your preferred layout, e.g body id="genesis-1a".
* @see layout.css
*/
?>
<body id="genesis-1b" <?php print $section_class; ?>>
<!--inizio salta menu-->
<div class="nascosto">
<strong>Drupal 6 navigazione veloce</strong>. <br />
<a href="#menu1">menu principale</a> |
<a href="#colsinistra">colonna di navigazione a sinistra</a> |
<a href="#contenuto1" >contenuto principale</a> |
<a href="#coldx">colonna di navigazione a destra</a> |
<a href="#sotto">piè di pagina</a>
<hr />
</div>
<!-- fine salta menu -->
<!--<div id="skip-nav">
<a href="#main-content"><?php print t('Skip to main content'); ?></a>
</div>-->
<?php if ($leaderboard): ?>
<div id="leaderboard" class="section region"><div class="region-inner">
<?php print $leaderboard; ?>
</div></div> <!-- /leaderboard -->
<?php endif; ?>
<div id="container" class="<?php print $classes; ?>">
<div id="header" class="clear-block">
<?php if ($site_logo or $site_name or $site_slogan): ?>
<div id="branding">
<?php if ($site_logo): ?>
<div id="logo"><?php print $site_logo; ?></div>
<?php endif; ?>
<?php if ($site_name): ?>
<?php if ($title): ?>
<h1 id="site-name"><strong><?php print $site_name; ?></strong></h1>
<?php else: /* Use h1 when the page title is empty */ ?>
<h1 id="site-name"><?php print $site_name; ?></h1>
<?php endif; ?>
<?php endif; ?>
<div id="indirizzo"><h2><span style="color: #726e32;font-family:font-family:Arial,Helvetica,sans-serif;font-weight:bold;"> <br>Residenze<br/>di classe<br/>a Firenze<br />
<br /></span></h2>
</div>
<?php if ($site_slogan): ?>
<div id="site-slogan"><?php print $site_slogan; ?></div>
<?php endif; ?>
</div> <!-- /branding -->
<?php endif; ?>
<?php if ($search_box): ?>
<div id="search-box"><?php print $search_box; ?></div> <!-- /search box -->
<?php endif; ?>
<?php if ($header): ?>
<div id="header-blocks" class="section region"><div class="region-inner">
<?php print $header; ?>
</div></div> <!-- /header-blocks -->
<?php endif; ?>
</div> <!-- /header -->
<!--inizio menu1 nascosto-->
<div class="nascosto">
<hr />
<strong><a name="menu1" id="menu1"></a>menu principale</strong>
<hr />
</div>
<!-- fine menu1 nascosto -->
<?php if ($primary_menu or $secondary_menu): ?>
<div id="nav" class="clear-block">
<?php if ($primary_menu): ?>
<div id="primary"><?php print $primary_menu; ?></div>
<?php endif; ?>
<?php if ($secondary_menu): ?>
<div id="secondary"><?php print $secondary_menu; ?></div>
<?php endif; ?>
</div> <!-- /nav -->
<?php endif; ?>
<!-- contenuto nascosto-->
<div class="nascosto">
<hr />
<strong><a name="contenuto1" id="contenuto1"></a>contenuto principale</strong>
<hr />
</div>
<!-- fine contenuto nascosto -->
<?php if ($secondary_content): ?>
<div id="secondary-content" class="section region"><div class="region-inner">
<?php print $secondary_content; ?>
</div></div> <!-- /secondary-content -->
<?php endif; ?>
<div id="columns"><div class="columns-inner clear-block">
<div id="content-column"><div class="content-inner">
<?php if ($mission): ?>
<div id="mission"><?php print $mission; ?></div> <!-- /mission -->
<?php endif; ?>
<?php if ($breadcrumb): ?>
<div id="breadcrumb" class="nav"><?php print $breadcrumb; ?></div> <!-- /breadcrumb -->
<?php endif; ?>
<?php if ($content_top): ?>
<div id="content-top" class="section region"><?php print $content_top; ?></div> <!-- /content-top -->
<?php endif; ?>
<!--// Two column Gpanel //-->
<?php if ($two_col_first or $two_col_second): ?>
<div class="two-col-50 gpanel clear-block">
<div class="section region col-1 first"><div class="inner">
<?php if ($two_col_first): print $two_col_first; endif; ?>
</div></div>
<div class="section region col-2 last"><div class="inner">
<?php if ($two_col_second): print $two_col_second; endif; ?>
</div></div>
</div>
<?php endif; ?>
<!--/end Gpanel-->
<div id="main-content">
<?php if ($title): ?><div id="title"><h1 class="title <?php if(!empty($node->field_titlehide[0]['value'])) {$titlehide = $node->field_titlehide[0]['value']; print $titlehide;} ?>"><?php print $title; ?></h1></div><?php endif; ?>
<?php if ($tabs): ?>
<div class="local-tasks"><div class="clear-block">
<?php print $tabs; ?>
</div></div>
<?php endif; ?>
<?php if ($messages): print $messages; endif; ?>
<?php if ($help): print $help; endif; ?>
<div id="content" class="section region">
<?php print $content; ?>
</div>
</div> <!-- /main-content -->
<!--// Three column Gpanel //-->
<?php if ($three_col_first or $three_col_second or $three_col_third): ?>
<div class="three-col-33 gpanel clear-block">
<div class="section region col-1 first"><div class="inner">
<?php if ($three_col_first): print $three_col_first; endif; ?>
</div></div>
<div class="section region col-2"><div class="inner">
<?php if ($three_col_second): print $three_col_second; endif; ?>
</div></div>
<div class="section region col-3 last"><div class="inner">
<?php if ($three_col_third): print $three_col_third; endif; ?>
</div></div>
</div>
<?php endif; ?>
<!--/end Gpanel-->
<?php if ($content_bottom): ?>
<div id="content-bottom" class="section region"><?php print $content_bottom; ?></div> <!-- /content-bottom -->
<?php endif; ?>
</div></div> <!-- /content-column -->
<!-- colonna sinistra nascosta -->
<div class="nascosto">
<hr />
<strong><a name="colsinistra" id="colsinistra"></a>colonna sinistra</strong>
<hr />
</div>
<!-- fine colonna sinistra nascosta -->
<?php if ($left): ?>
<div id="sidebar-left" class="section sidebar region"><div class="sidebar-inner">
<?php print $left; ?>
</div></div> <!-- /sidebar-left -->
<?php endif; ?>
<!-- colonna destra nascosta -->
<div class="nascosto">
<hr />
<strong><a name="coldx" id="coldx"></a>colonna destra</strong>
<hr />
</div>
<!-- fine colonna destra nascosta -->
<?php if ($right): ?>
<div id="sidebar-right" class="section sidebar region"><div class="sidebar-inner">
<?php print $right; ?>
</div></div> <!-- /sidebar-right -->
<?php endif; ?>
</div></div> <!-- /columns -->
<?php if ($tertiary_content): ?>
<div id="tertiary-content" class="section region clear-block"><div class="region-inner">
<?php print $tertiary_content; ?>
</div></div> <!-- /tertiary-content -->
<?php endif; ?>
<!-- pie di pagina nascosto -->
<div class="nascosto">
<hr />
<strong><a name="sotto" id="sotto"></a>piè di pagina</strong>
<hr />
</div>
<!-- fine pie di pagina nascosto -->
<?php if ($footer or $footer_message): ?>
<div id="foot-wrapper" class="clear-block">
<?php if ($footer_message or $feed_icons): ?>
<div id="footer-message"><?php print $footer_message; ?><?php print $feed_icons; ?></div> <!-- /footer-message/feed-icon -->
<?php endif; ?>
</div> <!-- /footer-wraper -->
<?php endif; ?>
</div> <!-- /container -->
<?php if ($footer): ?>
<div id="footer" class="section region"><div class="region-inner">
<?php print $footer; ?>
</div></div> <!-- /footer -->
<?php endif; ?>
<?php print $closure ?>
</body>
</html>
scusami se ti faccio un "ammonimento", ma cerca di non postare per intero le pagine PHP, che rendono illegibile il tuo post.
Ad ogni modo, mi sembra chiaro perchè non ti funziona, perchè non devi inserirlo in page.tpl.php ma in node.tpl.php, in quanto il "field" è un records dell'oggetto "node" e non dell'oggetto Page. Se ti serve in page.tpl.php dovresti in qualche modo Passarglielo tramite l'uso dei hook_prepocess_* oppure myTheme_preprocess_*
Slice2Theme Servizio per la conversione di Design in markup HTML e/o temi.
WeBrain Solution | Pillsofbits Of Bits
basta togliere il print del titolo in node.tpl.php...
http://www.de-signtn.it
Pessimo tutorial. Perchè non funziona, e non può funzionare mai...
Leggi meglio quello che ha detto kiuz:
Solo che il titolo è in page.tpl.php non node.tpl.php quindi come ha detto il buon kiuz:
Cioè devi recreare il $node in page.tpl.php
No. Per due motivi; prima perchè la domanda era "Nascondere il titolo in una pagina" non "in tutte le pagine" e secondo perchè quel titolo (in node.tpl.php) di solito e avvolto da un test per $teaser - cioè viene scritto solo quando il nodo fa parte di una lista (tipo views), e non quando è il contenuto di una pagina.
L'unico soluzione che conosco io è di fare come ha detto kiuz - e sicuramente non come spiegato in quel tutorial...
Più imparo, più dubito.
Chiedo scusa a kiuz per aver inserito un codice troppo lungo ma sono alle prime armi e non conoscevo la regola del forum.
Ho letto le risposte ma non essendo un programmatore non riesco a capire il significato di "Passarglielo tramite l'uso dei hook_prepocess_* oppure myTheme_preprocess_*".
Comunque per lo meno ho capito che quel metodo non funziona.
Volevo porre un'altra domanda collegata all'argomento.
Sempre girovagando per la rete ho trovato una proposta di questo tipo:
1) creare un content tipe nuovo (io ho creato no_title_page)
2) creare un "duplicato" del node.tpl.php con il nome node.no_title_page.tpl.php
3) eliminare da "node.no_title_page.tpl.php" il codice che fa stampare il titolo
se ho capito bene questo sistema presuppone il possibile collegamento fra un certo tipo di contenuto ed un file template che ne definisce le proprietà.
Volevo capire se questa cosa è giusta ed eventualmente in quale cartella del tema devo inserire il file "node.no_title_page.tpl.php" modificato.
Nel mio tema, sotto templates ho le varie cartelle (node, page, user, ecc).
Per far "agganciare"il nuovo template devo creare una specifica cartella o lo devo mettere nella cartella node assieme al node.tpl.php?
Il codice che stampa il titolo lo trovo fra questo:
<!--/end Gpanel-->
<div id="main-content">
<?php if ($title): ?><h2 id="page-title"><?php print $title; ?></h2><?php endif; ?>
<?php if ($tabs): ?>
<div class="local-tasks"><div class="clear-block">
<?php print $tabs; ?>
ma non vorrei elimnare troppo o troppo poco. Quale è la parte da togliere?
TKS PGF
Per modificare il look di un tipo di contenuto quello che hai scritto è corretto. Il file node.no_title_page.tpl.php logicamente sta dove trovi node.tpl.php.
Ma poi chiedi che codice togliere in page.tpl.php. Togli il codice da li e sarà tolto per tutte le pagine...
"Do not pass Go, do not collect €200"...
Più imparo, più dubito.
Scusa ma non mi sono fatto capire bene perchè ho fatto confusione quando ho copiato il codice e ne ho preso un pezzo da page invece che da node:
Il codice da toglire non è in: page.tpl.php ma in "node-no_title_page.tpl.php" che è un copia del "node.tpl.php".
Il codice che stampa il titolo lo trovo fra questo:
<div id="<?php print $node_id; ?>" class="<?php print $classes; ?>">
<div class="node-inner">
<?php if (!$page): ?>
<h2 class="node-title">
<a href="<?php print $node_url; ?>" rel="bookmark"><?php print $title; ?></a>
<?php print $unpublished; ?>
</h2>
<?php endif; ?>
ed è quì che non sono sicuro di quali modifiche devo fare per evitare che stampi il titolo.
Sigh. Togli:
<?php if (!$page): ?>
<h2 class="node-title">
<a href="<?php print $node_url; ?>" rel="bookmark"><?php print $title; ?></a>
<?php print $unpublished; ?>
</h2>
<?php endif; ?>
Ma, non sorprenderti se:
Quel codice dice "Se non siamo in modo pagina (quindi siamo in modo sommario) allora scrive il titolo, altrimenti non visualizzare il titolo"
Ripeto bisogna caricare (e testare il $node in page.tpl.php...
Vedi http://api.drupal.org/api/drupal/modules--system--page.tpl.php/6 e http://api.drupal.org/api/drupal/modules--node--node.tpl.php
Più imparo, più dubito.