News Manager 3.7 (beta) - draft docs

With NM 3.7 you can customize the post layout with components or template files, using some Wordpress-style PHP functions.

(Note: these docs are temporary and will be updated.)

Table of contents:

Layout code examples

Very basic layout

No internationalization, no image support, no author, doesn't check if there are no tags, no go-back link...

<?php if(!defined('IN_GS')) die(); /* <-- recommended for template files */ ?>
<div class="myPost">
    <h2><?php nm_render_title(); ?></h2>
    Published on <i><?php nm_render_date(); ?></i>
    <p>Tags: <?php nm_render_tags(); ?></p>
    <?php nm_render_content(); ?>
</div>

Default News Manager layout

Full layout for both single post view and lists of posts (main, archive, etc.)

<?php if(!defined('IN_GS')) die(); /* <-- recommended for template files */ ?>
<div class="nm_post">
    <h3 class="nm_post_title"><?php nm_render_title(); ?></h3>
    <p class="nm_post_date"><?php nm_e('PUBLISHED'); ?> <?php nm_render_date(); ?></p>
    <?php if (nm_must_render_author()) { ?>
        <p class="nm_post_author"><?php nm_e('AUTHOR'); ?> <em><?php nm_render_author(); ?></em></p>
    <?php } ?>
    <?php if (nm_must_render_image()) { ?>
        <div class="nm_post_image"><?php nm_render_image(); ?></div>
    <?php } ?>
    <div class="nm_post_content">
        <?php nm_render_content(); ?>
    </div>
    <?php if (nm_has_tags()) { ?>
        <p class="nm_post_meta"><b><?php nm_e('TAGS'); ?>:</b> <?php nm_render_tags(); ?></p>
    <?php } ?>
</div>
<?php if (nm_is_single()) { ?>
  <?php if (nm_has_goback_link()) { ?>
    <p class="nm_post_back"><a href="<?php nm_goback_link(); ?>"><?php nm_e('GO_BACK'); ?></a></p>
  <?php } ?>
<?php } ?>

Simpler default layout, only for lists of posts (main, archive, etc.) (This doesn't check if the "Go Back" link has to be rendered.)

<?php if(!defined('IN_GS')) die(); /* <-- recommended for template files */ ?>
<div class="nm_post">
    <h3 class="nm_post_title"><?php nm_render_title(); ?></h3>
    <p class="nm_post_date"><?php nm_e('PUBLISHED'); ?> <?php nm_render_date(); ?></p>
    <?php if (nm_must_render_author()) { ?>
        <p class="nm_post_author"><?php nm_e('AUTHOR'); ?> <em><?php nm_render_author(); ?></em></p>
    <?php } ?>
    <?php if (nm_must_render_image()) { ?>
        <div class="nm_post_image"><?php nm_render_image(); ?></div>
    <?php } ?>
    <div class="nm_post_content">
        <?php nm_render_content(); ?>
    </div>
    <?php if (nm_has_tags()) { ?>
        <p class="nm_post_meta"><b><?php nm_e('TAGS'); ?>:</b> <?php nm_render_tags(); ?></p>
    <?php } ?>
</div>

Custom post layout with Template Files

  • Create a nm folder in your theme. Inside this folder, create a file named post-default.php (for example) and paste the code in the example above
  • Enable NM Custom Settings and insert this: templateShowPost nm/post-default.php

You can also use specific layouts for different news page types. For example:

  • create a file post-single.php in the nm folder, with its custom code
  • add this to Custom Settings: single templateShowPost nm/post-single.php

(You can also do this for the other types: main, archive, tag, search.)

Like in GS template files, it is recommended to have something like this in the first line of every file:

<?php if(!defined('IN_GS')) die(); ?>

Custom post layout with Components

  • Create a component named e.g. nm-post-default and paste the code in the example above
  • Enable NM Custom Settings and insert this: componentShowPost nm-post-default

You can also use specific layouts for different news page types. For example:

  • create a component nm-post-single with its custom code
  • add this to Custom Settings: single componentShowPost nm-post-single (You can also do this for the other types: main, archive, tag, search.)

Note: It is not necessary to have the <?php if(!defined('IN_GS')) die(); ?> code in components, only in templates.

Template tags/functions reference

Normal display functions

Their output depends on normal and custom settings (e.g.titleLink, classPostTitleLink, DATE_FORMAT, more, etc.)

  • nm_render_title()
  • nm_render_date()
  • nm_render_content()
  • nm_render_tags()
  • nm_render_image()
  • nm_render_author()
  • nm_goback_link()

Conditional functions

They return true or false and can be used, for example, in if (...) { ... } sentences.

  • nm_has_tags()
  • nm_must_render_image()
  • nm_must_render_author()
  • nm_has_goback_link()

Raw display functions

They just output field values, independently of settings

  • nm_put_url()
  • nm_put_title()
  • nm_put_content()
  • nm_put_excerpt($length=150, $ellipsis='...', $break=false)
  • nm_put_date($format='Y-m-d')
  • nm_put_image($width=0, $height=0, $crop=false, $default='')

Return functions

They return raw field values that can be assigned to variables or whatever. If echoed, should be done be done with htmlspecialchars

  • nm_return_url()
  • nm_return_title()
  • nm_return_content()
  • nm_return_excerpt($length=150, $ellipsis='...', $break=false)
  • nm_return_date($format='Y-m-d')
  • nm_return_tags()
  • nm_return_image($width=0, $height=0, $crop=false, $default='')

Translation helper functions

If you want to make your custom layout work for any language selected for the front-end (texts like Published on, Tags, date format, ...) you can use these instead of writing the texts directly in the layout.

  • nm_e('TEXT')
    displays the translation for string TEXT, just like i18n('news_manager/TEXT')
  • nm_r('TEXT')
    returns the translation for string TEXT, just like i18n_r('news_manager/TEXT')