How to display the page name/title as an H1 heading

Permalink
Need to display the name of the page as an H1 heading on the page by default -- I thought this would be automatic but it doesn't seem to be...

Basically the equivalent of <?php the_title(); ?> in WordPress.

If this is a dumb question I apologize... seems utterly basic and I'm sure it's super-simple, but I just can't seem to figure it out...

Thanks.

dustin

platypusman
 
beebs93 replied on at Permalink Best Answer Reply
beebs93
In your template file (default.php for example):

<h1><?php echo htmlspecialchars($c->getCollectionName(), ENT_QUOTES, 'UTF-8'); ?></h1>


You could theorectially place this in the SITE_ROOT/themes/yourthemefolder/elements/header.php file, but then it would appear in system pages and the home page. Keeping it in your template files gives you a bit more control.
platypusman replied on at Permalink Reply
platypusman
Thanks very much!

I did find a solution, just a moment ago, here:http://www.concrete5.org/community/forums/customizing_c5/page_title...

It's only slightly different from yours, but this code snippet will display the meta title if there is one, otherwise display the "collectionName" which is equivalent to the page title:

<?php
   //get the meta_title
   $metaTitle = $c->getCollectionAttributeValue('meta_title');
   //if page has a meta_title
   if(!empty($metaTitle)) {
      //print the meta_title
      print $metaTitle;
   } else {
      //otherwise print the default page title
      print $c->getCollectionName(); 
   }
?>


Am I the only one who finds it odd that the page name isn't displayed on the page as an H1 by default?? Ah well.
beebs93 replied on at Permalink Reply
beebs93
Yeah, that will technically work, however, meta_title was not intended to work in this way. If you look in the /concrete/elements/header_required.php you will notice that it is meant to override the <title> in the HTML <head>.

You could potentially step on your toes down the road, so if having two different page names is necessary then I'd suggest making a new page attribute and use that as an override.

<?php
$strName = trim($c->getAttribute('override_page_attribute'));
if(strlen($strName) == 0) $strName = $c->getCollectionName();
?>
<h1><?php echo htmlspecialchars($strName), ENT_QUOTES, 'UTF-8'); ?></h1>
platypusman replied on at Permalink Reply
platypusman
Thanks, good to know.

For what I need your code works perfectly, so I'll just stick with that instead.