User guide
Theming Tutorial March 02nd, 2009
- Part 1: Theme Basics
- Part 2: Making a theme
- Part 3: Advanced Theme Functionality
- Part 4: Theming Zenpage
Part 1: Theme Basics
What should I know before making a custom theme?
During the process of this article, we will be looking at the basic files and function elements that are necessary to form a working Zenphoto theme, We’ll use the default theme as an example. We will not go into every single detail of the code because we assume that you have an good understanding of (X)HTML and CSS. You should also have a basic understanding what PHP is and how PHP code is put into a webpage and communicates with the server and returns information back to the client.
For more detailed information on the Zenphoto template functions please visit our functions documentation and it’s accompaning How To Read The Zenphoto Functions Guide article.
What is a theme?
In technical terms, it’s a set of files that use a markup language ((X)HTML and CSS) and embedded PHP code to dynamically create the layout and style of your gallery. In other words, a theme is just a way to give your gallery a different look.
Where are the theme files located?
By default, when you first install Zenphoto, you should have a file structure that looks similar to the image on the left. You have the “root” or main folder of Zenphoto, then in it you have four other folders named albums, cache, themes, and zp-core. The themes folder is where the default themes exist, where you should install new themes that you’ve downloaded, and where you will put all your new themes. Zenphoto comes with four themes: default, example, effervescence_plus and stopdesign.
Where do I find themes and how can I install a theme designed by someone else?
You can find all known custom themes at our themes page, or from the theme creator’s site.
Usually, the distribution of a theme comes with instructions on how to install the theme. For those instances where instructions don’t exist, here is a basic set of installation instructions for installing themes:
- Download the theme of your choice.
- Expand the zip archive to a local folder.
- Upload the extracted folder (keeping the underlying folder structure intact) to your /themes directory.
- Go into your admin > themes tab and choose your theme.
- View your gallery with the new theme in place!
Note: Some themes have custom mods or things that need to be changed in addition to the normal theme installation. So take care to note in the theme distribution what these may be before you install.
How does a theme work?
Themes are done in a pretty straightforward way. They’re just PHP files that use a set of theme functions (from zp-core/template-functions.php) to display the albums or images in any way. The current theme is selected in the admin themes panel. (Admin uses the file theme_description.php within the theme’s folder as the sorce of its information about the theme.) The root index.php file then looks at the URL arguments (album, image, etc. or lack thereof) and decides whether to load the theme’s index file, album page, or image page. Pretty simple.
Theme Structure
Here’s a brief description of the basic files that are needed for a standard theme:
These are the required basic files every theme must have:
- theme_description.php – This is the description file which gives ZenPhoto information about your theme. This information is displayed in the themes page of the ZenPhoto admin backend. Older themes before ZenPhoto 1.2 may use a theme.txt file for the same purpose.
- theme.png – This is the theme thumbnail used in the Options page of ZenPhoto.
- index.php – This is the default php file. It’s read and displayed when someone visits your main gallery page.
- album.php – This page is displayed when someone clicks on an album link from your gallery page (index.php). It then displays all the pictures in the selected album as thumbnails.
- image.php – This page is displayed when someone clicks on a specific thumbnail picture on your album page (album.php). It then displays the selected picture (the sized image), all it’s comments, and the “add comment” form.
The following files are optional as they are not required for a basic functioning theme:
- search.php – The page that displays search results. Actually this page is optional if you don’t want to use the search on your site. It’s included in all standard themes.
- archive.php – A custom page that is used to display the monthly archive and a tag cloud. It’s included in all standard themes except stopdesign.
- themeoptions.php – This provides the option handling interface used by the admin backend on the theme options page.
- slideshow.php – A page that displays the slideshow. The design is generic so that it works with all themes without design adjusting, just a black background with the image on it, but it’s possible to make it look like your other theme pages. Related files that are required to run the slideshow are the slideshow.css and the slideshow-controls.png and the slideshow plugin must be installed and activated.
A diagram that shows the relations of the theme files:
Part 2: Making a Theme
We will now look at the necessary theme pages and the basic structure of these file that Zenphoto needs to process a theme. You can then take this knowledge and use it to create your own theme. Again, we won’t discuss any functions (or any (X)HTML or CSS styling) in detail.
More info on specific functions can be found in our functions guide.
theme_description.php
<?php // Zenphoto theme definition file $theme_description['name'] = 'Default'; $theme_description['author'] = '<a href="http://www.noscope.com" target="_blank">Joen Asmussen</a> and <a href="http://www.levibuzolic.com" target="_blank">Levi Buzolic</a>'; $theme_description['version'] = '1.5'; $theme_description['date'] = '10/20/2007'; $theme_description['desc'] = "The default theme in 4 distinct flavors. After choosing this theme you can pick the theme color by going to the Admin Options tab and changing the <em>Theme colors</em> option."; ?>
First of all, the first line is REQUIRED. This line will tell ZenPhoto that this file is about to describe a theme. Zenphoto will then look at the rest of the information and process it. The information is set up as key-value relationships using the format key::value. This means that whatever the name of the key, the value is shown after the “=” . So now let’s take a look at the list of keys and what they’re for.
- name – This is the name of the theme.
- author – This is the theme author’s name.
- version – This should be the version number of the theme.
- date – This should be the last known date of modification of the theme.
- description – This should be a short description of the theme. It would be a good idea if you include within the description the Zenphoto version for which you actually made this theme.
So just change the values of the keys to match your theme.
theme.png/theme.gif/theme.jpg
This will most likely be the very last file that you create for your theme; it’s an image used to represent your theme. This image can either be a .png, .gif, or .jpg and the dimensions of the file should be 150 x 150px. Most themes use a screenshot of thefinished theme for this image.
index.php
Look at the code in index.php, it’s all just a standard xHTML-based webpage, but we’ll try and explain some of the PHP code that’s in there.
<?php if (!defined('WEBPATH')) die(); ?>
This bit of code makes sure that the configuration for Zenphoto is setup correctly, if not it will stop everything right here. (There’s no point in processing the rest of the webpage if the configuration is incorrect, right?)
<?php printGalleryTitle(); ?>
As you can read from the function name, this function will place the actual name of the Gallery Title on the displayed page. So for example, if the title of your gallery were John’s Flower Garden then the code would go from looking like this:
<title><?php printGalleryTitle(); ?></title>
to like this:
<title>John's Flower Garden</title>
The next bit of PHP code:
<?php echo $_zp_themeroot ?>
Tells ZenPhoto to show the current path to the current theme’s root directory. This is why it’s used in the following context:
<link rel="stylesheet" href="<?php echo $_zp_themeroot ?>/index.css" type="text/css" />
This will give the correct path to the .css file.
<?php zenJavascript(); ?>
This will include some theme supporting JavaScript that, for instance, allows the logged in administrator to dynamically edit the description and title of your images and albums using AJAX.
<?php if (getOption('Allow_search')) { printSearchForm(''); } ?>
If you set it in the Allow_search options this will print the search form.
<?php printHomeLink('', ' | '); echo getGalleryTitle(); ?>
This is actually a short breadcrumb navigation that will print this if you use Zenphoto within a website and set the link to that site within the options:
Site name | Gallery title
The following code is the main chunk of code for this file. It’s the so called “album loop” that lists all the albums in the gallery:
<?php while (next_album()): ?> <div class="album"> <div class="albumthumb"><a href="<?php echo getAlbumLinkURL();?>" title="<?php echo getAlbumTitle();?>"> <?php printAlbumThumbImage(getAlbumTitle()); ?></a></div> <div class="albumtitle"> <a href="<?php echo getAlbumLinkURL();?>" title="<?php echo getAlbumTitle();?>"></a> <?php printAlbumTitle(true); ?></div> </div> <?php endwhile; ?>
Let’s take this line by line. First you’re starting a while loop in PHP and tell ZenPhoto that ‘as long as there’s a another album that’s next in the list of albums, do the following code’. The ‘code’ that you want Zenphoto to process for every album is placed in between the the lines '<?php while (next_album()): ?>' and '<?php endwhile; ?>'
That is why when you look at the xHTML source from your browser you see a div with an album class more than once, because it will put every album into a div tag with the album class.
Now inside that while loop you will see more PHP code. The functions getAlbumLinkURL(), getAlbumTitle(), printAlbumThumbImage(), and printAlbumTitle() are all theme functions of which we won’t explain because there are just too many to create a list here and you can also look them up in the theme function reference. However it’s pretty obvious what they do just by looking at the function names. Keep in mind that all these functions provide information about the album and this information will be repeated for each album in the list of albums while going through the while loop.
Note: If you password protect an album via the admin backend and have the image display use lock image option set, Zenphoto uses a default image err-passwordprotected.gif as a replacement for the actual album thumb. This image is located within /zenphoto/zp-core/image/ folder. But a theme can have its own image, all that needs to be done is to place a custom image of the same name like this: /zenphoto/<themefolder>/images/err-passwordprotected.gif.
<?php printPageListWithNav('<', '>'); ?>
This code will create an unordered list of links that link to the number of pages of albums in the gallery. So, for example, if you have three pages of albums, it will create the follwing code:
<ul class="pagelist"> <li class="prev"><span class="disabledlink"><</span></li> <li class="current"><a href="http://www.zenphoto.org:8080/zp" title="Page 1 (Current Page)">1 </a> </li> <li><a href="http://www.zenphoto.org:8080/zp/page/2/" title="Page 2">2</a></li> <li><a href="http://www.zenphoto.org:8080/zp/page/3/" title="Page 3">3</a></li> <li class="next"><a href="http://www.zenphoto.org:8080/zp/page/2/" title="Next Page">></a></li> </ul>
Most themes then contain a footer that prints the gallery rss link and the link to the (optional) archive page:
<div id="credit"><?php printRSSLink('Gallery','','RSS', ' | '); ?>
<a href="?p=archive"><?php echo "Archive View"; ?></a> | <?php echo "Powered by"; ?>
<a href="http://www.zenphoto.org" title="<?php echo 'A simpler web photo album'; ?>">
zenphoto</a></div>
This is followed by the admin tool box that lets you directly jump to the admin backend if you are logged in, althought not necessary for a theme, this can be very useful:
<?php printAdminToolbox(); ?>
album.php
This page is almost exactly identical to index.php, so we won’t explain everything again. But there are some differences though:
<?php if (!defined('WEBPATH')) die(); $firstPageImages = normalizeColumns('2', '6'); ?>
As you might notice the second part starting with $firstPageImags is new. Basically (very simplified view) it figures out how many images and albums will fit on a page. In particular, it figures this out for the “transition” page where there are both album and image thumbnails on the same pagem which is not unusual if you have subalbums.
Then again we have the expanded breadcrumb navigation, that now prints additionally the album title, too.
<?php printHomeLink('', ' | '); ?>
<a href="<?php echo getGalleryIndexURL();?>" title="<?php echo 'Albums Index'; ?>">
<?php echo getGalleryTitle();?></a> | <?php printParentBreadcrumb(); ?></span>
<?php printAlbumTitle(true);?></h2>
The <?php printParentBreadcrumb(); ?> part is for the breadcrumb display if you have one or more subalbum levels.
The next necessary element is then again the “album loop” you know already from index.php, that now displays the subalbums if available.
But now comes a really new part, the “image loop”:
<?php while (next_image(false, $firstPageImages)): ?><div class="image"> <div class="imagethumb"> <a href="<?php echo htmlspecialchars(getImageLinkURL());?>" title="<?php echo getImageTitle();?>"> <?php printImageThumb(getImageTitle()); ?></a> </div> </div><?php endwhile; ?>
This works just like the “album loop” but displays the thumbnails of the images that are in the current selected album.
The remaining code is then again the page navigation and the footer that is the same as on index.php, except that you might want to use the album rss link instead of the gallery rss link.
image.php
Since you should be used to the theme functions by now, we won’t go into what everyone does, but we’ll try and explain the more difficult bits of code.
Right at the top of this file (right before you define where the AJAX code goes) you’ll notice a new bit of JavaScript.
function toggleComments() { var commentDiv = document.getElementById("comments");
if (commentDiv.style.display == "block") { commentDiv.style.display = "none";
} else { commentDiv.style.display = "block"; } } </script>
This code will basically allow you to toggle whether or not you want the comments to show or not. Just use it in a link and use the OnClick method of a link to run the toggleComments() function.
<div class="navigation"> <?php if (hasPrevImage()) { ?>
<a href="<?php echo getPrevImageURL();?>" title="Previous Image"><</a><?php } ?>
<?php if (hasNextImage()) { ?><a href="<?php echo getNextImageURL();?>" title="Next Image">>
</a><?php } ?> </div>
If there is an image (in the list of images) previous than the one being viewed, tgis creates a link to that previous image with the text “<”. Then, if there is an image (in the list of images) following the one being viewed, it creates a link to the following image with the text “>”.
Again we will use the breadcrumb naviagtion that is now extended again with the image title:
<?php printHomeLink('', ' | '); ?>
<a href="<?php echo getGalleryIndexURL();?>" title="<?php 'Albums Index'; ?>">
<?php echo getGalleryTitle();?></a> |
<?php printParentBreadcrumb("", " | ", " | ");
printAlbumBreadcrumb("", " | "); ?> </span>
<?php printImageTitle(true); ?>
The next code display the actual image – we call it the “sized image” to separate it from the full size image, that is linked to the full image and if available the image description :
<div id="image"><a href="<?php echo getFullImageURL();?>" title="<?php echo getImageTitle();?>"> <strong><?php printDefaultSizedImage(getImageTitle()); ?></strong> </a> </div> <div id="narrow"><?php printImageDesc(true); ?>
This is followed by the display of the EXIF information:
<?php if(getImageEXIFData()) {echo "<div id=\"exif_link\">
<a href=\"#TB_inline?height=345&width=300&inlineId=imagemetadata\"
title=\"Image Info\" class=\"thickbox\">Image Info
</a></div>"; printImageMetadata('', false); } ?>
If you want to protect the display of your sized image and/or the comments by album or gallery password, you should place this “if clause” around the whole part of the above code from sized image to comments like this:
<?php if (!checkForPassword()) { ?> stuff for sized image, comments, comments form <?php }; ?>
The remaining is again the same as on album.php.
search.php
This is the last of the actual required theme page. It’s actually nearly the same as the album.php since it does displaying albums and image. But this time the search results and not fixed albums.
<div id="padbox"> <?php if (($total = getNumImages() + getNumAlbums()) > 0) {
if ($_REQUEST['date']){ $searchwords = getSearchDate();
} else { $searchwords = getSearchWords(); }
echo "<p>Total matches for <em>".$searchwords."</em>: $total</p>"; } $c = 0; ?>
This is the actual new part that fetches the search queries someone entered and prints the how many matches there are. This is then followed by the already known “album loop” and “image loop” from album.php. After that the following code is added, that as you see is used if there are no matches.
<?php if ($c == 0) { echo "<p>Sorry, no image matches. Try refining your search.</p>"; }
The remaining is once again the same as on all other theme pages.
Adding the comments section
You can add comments to album.php and image.php. Additionally also to Zenpage’s pages.php and news.php.
Since Zenphoto 1.2.6 the comment handling code has been transfered to the comment_form plugin. All you need to do is to put this code where you want the comment form and the comment display.
<?php
if (function_exists('printCommentForm')) { ?>
<div id="comments">
<?php printCommentForm(); ?>
</div>
<?php } ?>
You can of course modify the look of the comment section via CSS or you could even make your own comment form by changeing the file zp-core/plugins/comment_form/comment_form.php.
Part 3: Advanced Theme Functionality
This part of our tutorial is about the more advanced functionalitly you can add to your theme.
Custom pages with the example of archive.php and slideshow.php
“Custom pages” are additional pages that do not display actual gallery stuff like albums or images. You can have multiple custom pages that are called with the url
zenphoto/index.php?p=pagetitle (non mod_rewrite)
or
zenphoto/page/pagetitle (mod_rewrite)
In general a custom page is just like index.php but with the album loop removed. These pages can be used as an “about” or “references” page for example, but the content needs to be hardcoded and can not be adminstrated by zenphoto. (Of course, you can created theme options to allow customization of these pages from the admin theme options tab.)
You can use some of the more general theme functions as archive.php does.
Archive.php is used to display links that organize your images by month & year, and a tag cloud of the most used tags:
<?php if (!checkForPassword()) {?>
<div id="archive"><?php printAllDates(); ?></div>
<div id="tag_cloud"> <p>Popular Tags</p>
<?php printAllTagsAs('cloud', 'tags'); ?> </div> <?php } ?>
slideshow.php is actual a slim custom page that is outside the actual theme since it is meant to be used as a generic slideshow page. It consists of a basic html structure and the function
<?php printSlideShow(); ?>
Separation of the gallery and the index page
You may wish to have an introductory page to your website but still keep the look and feel of the gallery for visitors viewing your images. This can easily be done by using the theme option custom index page. If you have an existing zenphoto gallery the easiest way to accomplish this task is to rename your current theme index.php script to something else, say gallery.php. Create your new index.php script to introduce your site. Include on it a link to http://yoursite.com/zenphoto/page/gallelry (assuming you named your old index file gallery.php and you installed zenphoto in the folder zenphoto). Set the custom index page option to gallery and your are all set.
Custom functions
Custom functions can be used to add additional functionality to your theme. Actually these are just an extra template functions that are placed as a extra PHP file within your theme’s folder. Name this theme file functions.php and it will be loaded automatically on every theme page to make the custom functions available.
Theme options
Themes may create options that change the behavior or appearance of the theme. (All the distributed themes have options for these reasons.) Options are defined by PHP code in a file called themeoptions.php which is located in your theme folder. The file is optional, if you have no options you need not have themeoptions.php. Theme options are one class of Zenphoto plugins. Plugins are described here. You define the options in this code and make use of them in your theme by calling the function getOption() passing the option name. (It is a good idea to be sure any unique options you create have unique names so that they don’t conflict with options some other theme builder might have made.)
Some of the ’standard’ theme options (as defined by the distributed themes) are: ‘Allow_comments’, ‘Allow_search’, and ‘Theme_colors’. These are used in the distributed themes to enable comment forms, enable serach forms, and select a CSS for the theme. See the default theme for examples.
Themeoptions are a class of Zenphoto Plugin so reading about the plugin architecture might also be of some value.
Overriding options for special theme effects
If your theme has special needs for some options it is possible to override temporarily the options as set in the Administrative back end. Cases where this might be useful are, for instance, to insure that the theme looks well balanced when there are multiple album thumbs or image thumbs in a row. The theme may then wish to change the albums per page option (images per page option) so that it is a multiple of the number that will fit in a row. (The standard themes all do this.)
It would not be nice, however, for a theme to permanantly change the option as it would impact other themes that might get used. The setOption() function of zenphoto has provided a means to temporarily change an option without updating the options database. There is a third parameter the the setOption() function, $persistent, which is defaulted to true. Passing false to this parameter tells setOption() to change the value of the option in memory but not in the database.
The duration for an option set non-persistent is the scope of the script from where it is set until the script ends. This means that each script that relies on the transient value of the option must set it.
Special images
Zenphoto has several special images that a theme can replace it it wished. These are:
imageDefault.pngwhich is used for album thumbnails when there are no images in the album.multimediaDefault.pngwhich is the default image for video thumbnails.err-passwordprotected.gifwhich is used (optionally) as a standin for the thumbnail of an album which is password protected and the viewer has not supplied the password.
and
A theme can override the images that come with Zenphoto by placing a same named image in a folder named images within the theme folder.
Special scripts “>
There are currently two special PHP scripts that can be used to enhance your theme. They are optional, so if you have not created them, a standard behavior will replace them.
404.php: If your theme contains this script it will be invoked whenever a page not found contition is raised by Zenphoto. Creating a script of this name allows you to control the presentaton of the page not found error. Each of the Zenphoto distributed themes contains such a script that you can take as an example.
password.php (post 1.2.5): Default password protection handling will check passwords in the image and album loops. If an album is password protected, no subalbums or images will be returned from the loops. Instead, a password form will be presented. Additional protection can be achieved by placing if (!checkforPassword(true) { } block around content you wish hidden on password protected pages.
With the 1.2.6 release you can instead create a password.php script in your theme folder. If such a script exists, it will be loaded in place of the target Zenphoto page. This allows you to completely control the presentation of the password protected content. Each of the distributed themes contains such a script for your use as an example.
Separate theme translations (post 1.2)
If you provide a theme as a third party, it’s translation is naturally not included with Zenphoto’s general translation file. But with post Zenphoto 1.2 you can have an independent translation file for your theme. Zenphoto uses gettext for translations. Please visit our translating tutorial for more detailed information about that.
To set up your theme for separate gettext translation, you just need to place the following function on top of each theme file:
<?php setThemeDomain(”<theme name>”); ?>
This function tells Zenphoto that this theme uses it’s own translation.
You also need need to have a locale folder set up within your theme’s folder this way:
/themes/<theme name>/locale/ /themes/<theme name>/locale/<language locale>/LC_MESSAGES/ /themes/<theme name>/locale/<language locale>/LC_MESSAGES/<theme name>.po /themes/<theme name>/locale/<language locale>/LC_MESSAGES/<theme name>.mo
It is important that you then only parse your theme’s folder with Poedit or another gettext editor.
Sophisticated theme design
Zenphoto is actually not limited to the already described standard theme way. Besides the fact that all template functions have a “print” variant that prints a full convenient HTML setup there is also (nearly) always a “get” variant that just returns raw data (strings, objects, array etc.) to build customized functions for special needs.
Zenphoto also provides an object orientated framework for advanced users with coding knowledge to do different and more sophisicated things that are bascially only limited by your abilities.
See the object model framework tutorial and the functions documentation for more details.
Part 4: Theming Zenpage
Zenpage theme basics
This part will give you only a basic overview how to setup your theme for the CMS plugin Zenpage. It will not explain every detail. For more about the functions in detail please visit the functions guide and take a look at the included zenpage-default theme.
Zenpage hooks on Zenphoto’s custom page feature and therefore requires two new custom pages to be available with your theme folder: pages.php and news.php. The name can be changed if really required for a certain language but this is only recommended for more advanced users. You can read about it in the FAQs.
Generally you can use all general Zenpage functions on all Zenphoto theme pages as you can in turn use all general Zenphoto functions on these two new pages. Although some functions are limited only to pages.php and news.php to work correctly.
pages.php
This theme page is the simplest of the both since it will only show one page at the time, so we start with it.
For a general site you just need the headline and the content:
<h2><?php printPageTitle(); ?></h2><?php printPageContent(); ?>
You can of course customize this with printExtraContent() or the printCodeblock() functions.
If you like to have comments on your page you have to add the comments part, too. A pages comments part is quite similar to the normal Zenphoto comments part. The only difference is that it uses to specific Zenpage options getOption('zenpage_comments_allowed')and zenpageOpenedForComments() that allow to set these independently from the general Zenphoto comments setting. See adding the comments section for details.
The last thing you have to add is the admin tool box:
<?php printAdminToolbox(); ?>
news.php
This page is a little more complicated because it showe either the single news article and the news loop. The general structure is single news articles or news loop. First we check if this is a single news article:
<?php if(is_NewsArticle()) { ?>
If it is we show it. This two functions print links to the next or previous articles:
<?php printPrevNewsLink(); ?> <?php printNextNewsLink(); ?>
Note that these do not work when in CombiNews mode to avoid confusing since images will not be included.
Next we need the article itself with title, content and a few other functions that should be quite self explaining:
<h3><?php printNewsTitle(); ?></h3> <?php printNewsDate();?><?php echo gettext("Comments:"); ?><?php echo getCommentCount(); ?> <?php printNewsCategories(", ",gettext("Categories: "),"newscategories"); ?><?php printNewsContent(); ?>
Now if you like to have comments you need again the comments part that we already know from the pages.php section.
Now we have to close the <?php if(is_NewsArticle()) { ?> statement from the beginning and open the else part for the news loop:
} else {
The news loop itself is again quite similar to two structures you know from Zenphoto, the next_image() and the next_album() loops. The content itself is actually nearly the same as for a single news article:
while (next_news()): ;?> <h3><?php printNewsTitleLink(); ?></h3><?php printNewsDate();?><?php echo gettext("Comments:"); ?><?php echo getCommentCount(); ?><?php printNewsCategories(", ",gettext("Categories: "),"newscategories"); ?><?php printNewsContent(); ?><p><?php printNewsReadMoreLink(); ?></p><?php endwhile; ?>
Closing is a a function that is similar to the pagination of Zenphoto’s album and index page:
<?php printNewsPageListWithNav(gettext('next »'), gettext('« prev')); ?>
Then you have to close the else statement that we openend above:
<?php } ?>
Last but not least you can again add the admin toolbox.
<?php printAdminToolbox(); ?>
Adding search results for Zenpage items on search.php
Search results for Zenpage news articles and pages are not paginated and only shown on the first search results page.
Since Zenpage is an optional plugin we need to make sure that we set Zenpage results to 0 if the plugin is not enabled to avoid errors:
$zenpage = getOption('zp_plugin_zenpage');
if ($zenpage && !isArchive()) {
$numpages = getNumPages();
$numnews = getNumNews();
$total = $total + $numnews + $numpages;
} else {
$numpages = $numnews = 0;
}
Now we add the code to show the Zenpage results on the first results page only:
<?php
if ($_zp_page == 1) {
if ($numpages > 0) {
$number_to_show = 5;
$c = 0;
?>
</h2>
<h3><?php printf(gettext('Pages (%s)'),$numpages); ?></h3>
<ul>
<?php
while (next_page()) {
$c++;
?>
<li>
<h4><?php printPageTitlelink(); ?></h4>
<p><?php echo shortenContent(strip_tags(getPageContent()),80,getOption("zenpage_textshorten_indicator")); ?></p>
</li>
<?php
}
?>
</ul>
<?php
}
if ($numnews > 0) {
$number_to_show = 5;
$c = 0;
?>
<h3><?php printf(gettext('Articles (%s)'),$numnews); ?></h3>
<ul>
<?php
while (next_news()) {
$c++;
?>
<li>
<h4><?php printNewsTitleLink(); ?></h4>
<p><?php echo shortenContent(strip_tags(getNewsContent()),80,getOption("zenpage_textshorten_indicator")); ?></p>
</li>
<?php
}
?>
</ul>
<?php
}
}
News on index.php
This option allows to turn the theme index.php into the first page of the news section (all further ones will be displayed on news.php). All you have to do to use this is to copy the complete next_news() loop to your index.php.
It is recommended to limit the display to the first index.php page because the news loop uses the same variable for paging as index.php does. So you will get some probably unexpected results if you don’t limit this.
Alternatively you could also skip albums on index.php and use the printAlbumMenu() plugin to access them instead.
Showing Zenpage content on other theme pages
You can use the get/printPageContent(), get/printExtraContent() and get/printCodeblock() functions to show published or unpublished pages’ content, extracontent or codeblocks elsewhere. More info about these functions’ parameters on the documentation.
If you need more fields like author or date, you probably should do this with the class object directly:
$page = new ZenpagePage("<titlelink of the page to get>");
Then you can call each field with <?php echo $page->getId(); ?> for example. Note that the title, content and extracontent fields support the multi-lingual feature, so that they need to be called like this:
<?php echo get_language_string($page->getTitle()); ?><?php echo get_language_string($page->getContent()); ?><?php echo get_language_string($page->getExtraContent()); ?>
Of course this works similar for news articles, too. For more info about the Zenpage object methods please see the the object model framework tutorial and the functions documentation.
The CombiNews feature
This actually does not really need any special theming. Zenpage will just internally use the normal functions to show the lastest image within the normal loop as if they were news articles. They are still independed.
But you have some additional functions to use with them. For example there is:
<?php getNewsType(); ?>
This will print if the entry is a news article or an image or a movie. More detailed info on the functions guide.
Since images, movies or audio files do not have categories, but albums you can show this, too:
<?phpif(is_GalleryNewsType()) {echo gettext("Album:")."<a href='".getNewsAlbumURL()."' title='".getBareNewsAlbumTitle()."'> ".getNewsAlbumTitle()."</a>";} else {printNewsCategories(", ",gettext("Categories: "),"newscategories");}?>
If the entry is an image etc it prints a link to the album it belongs to. If not is prints the list of the news article categories.
