Skip to content

Template Code Snippets

risingisland edited this page Aug 23, 2024 · 1 revision

Short pieces of code to use in Template-files (from the Forum).


returnPageContent()

<?php returnPageContent(); ?>

Caching/Indexing function can be used to check the page content (example: conditionals).


global $content;

<?php global $content; ?>

Similar to returnPageContent() this can be used to check the page content.


output author

<?php echo $data_index->author; ?>
<?php getPageField(return_page_slug(),'author'); ?>
<?php echo stripslashes(html_entity_decode($data_index->author, ENT_QUOTES, 'UTF-8') ); ?>

The last example is for output of Unicode characters.


conditional by template

<?php if ($template_file == 'name-of-template.php') {
...

If used in a component, first do:

global $template_file;

conditional by page (slug)

<?php if (return_page_slug() == 'contact') {
...

template ready for but not requiring a plugin

If for example you want to make a template ready for the Custom Title plugin but to work normally without it:

<title>
		<?php if (function_exists('get_custom_title_tag'))
		{echo(get_custom_title_tag());}
		else { get_page_clean_title(); }  ?>
</title>

Clone this wiki locally