Hit counter

While I'm asking questions...I have another.

I do not see a hit counter in my albums or where to activate/deactiate one. Here http://www.zenphoto.org/index.php?s=hit+counter it says a hit counter is now enabled by default.

I am using version 1.2.2 and the default theme set to "dark".

Comments

  • Paste this in image.php

    <?php
    $h = getHitcounter();
    if ($h == 1) {
    echo "<p>".gettext('1 view')."</p>";
    } else {
    echo "<p>".sprintf(gettext('%u views'),$h)."</p>";
    }
    ?>
  • Anywhere in image.php in particular?

    <?php if (!defined('WEBPATH')) die(); $themeResult = getTheme($zenCSS, $themeColor, 'light'); $firstPageImages = normalizeColumns('2', '6');?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php zenJavascript(); ?>
    <title><?php echo getBareGalleryTitle(); ?> | <?php echo getBareAlbumTitle();?> | <?php echo getBareImageTitle();?></title>
    <link rel="stylesheet" href="<?php echo $zenCSS ?>" type="text/css" />
    <link rel="stylesheet" href="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.css" type="text/css" />
    <script src="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.js" type="text/javascript"></script>
    <script type="text/javascript">
    function toggleComments() {
    var commentDiv = document.getElementById("comments");
    if (commentDiv.style.display == "block") {
    commentDiv.style.display = "none";
    } else {
    commentDiv.style.display = "block";
    }
    }
    </script>
    <?php printRSSHeaderLink('Gallery',gettext('Gallery RSS')); ?>

    </head>

    <body>

    <div id="main">

    <div id="gallerytitle">
    <div class="imgnav">
    <?php if (hasPrevImage()) { ?>
    <div class="imgprevious">" title="<?php echo gettext("Previous Image"); ?>">« <?php echo gettext("prev"); ?></div>
    <?php } if (hasNextImage()) { ?>
    <div class="imgnext">" title="<?php echo gettext("Next Image"); ?>"><?php echo gettext("next"); ?> »</div>
    <?php } ?>
    </div>
    <h2><span><?php printHomeLink('', ' | '); ?>" title="<?php gettext('Albums Index'); ?>"><?php echo getGalleryTitle();?>
    | <?php printParentBreadcrumb("", " | ", " | "); printAlbumBreadcrumb("", " | "); ?>
    </span> <?php printImageTitle(true); ?>
    </h2>

    </div>

    <!-- The Image -->
    <?php if (!checkForPassword()) { ?>
    <div id="image">
    " title="<?php echo getBareImageTitle();?>">

    <?php
    if (function_exists('printUserSizeImage')) {
    printUserSizeImage(getImageTitle());
    } else {
    printDefaultSizedImage(getImageTitle());
    }
    ?>


    <?php if (function_exists('printUserSizeImage')) printUserSizeSelectior(); ?>
    </div>

    <div id="narrow">
    <?php printImageDesc(true); ?>
    <?php if (function_exists('printSlideShowLink')) printSlideShowLink(gettext('View Slideshow')); ?>
    <hr />
    <?php
    if (getImageEXIFData()) {echo "<div id=\"exif_link\">".gettext("Image Info")."</div>";
    printImageMetadata('', false);
    }
    ?>
    <?php printTags('links', gettext('Tags:').' ', 'taglist', ''); ?>
    <br clear=all />

    <?php if (function_exists('printImageMap')) printImageMap(); ?>

    <?php if (function_exists('printImageRating')) { printImageRating(); }?>

    <?php if (function_exists('printShutterfly')) printShutterfly(); ?>

    <?php if (getOption('Allow_comments')) { ?>
    <div id="comments">
    <?php $num = getCommentCount(); echo ($num == 0) ? "" : ("<h3>".sprintf(gettext('Comments (%u)'), $num)."</h3><hr />"); ?>
    <?php while (next_comment()){ ?>
    <div class="comment">
    <div class="commentmeta">
    <span class="commentauthor"><?php printCommentAuthorLink(); ?></span>
    </div>
    <div class="commentbody">
    <?php echo getCommentBody();?>
    </div>
    <div class="commentdate">
    <?php echo getCommentDateTime();?>
    <?php printEditCommentLink(gettext('Edit'), ' | ', ''); ?>
    </div>
    </div>
    <?php }; ?>

    <?php if (OpenedForComments()) { ?>
    <div class="imgcommentform">
    <!-- If comments are on for this image AND album... -->
    <h3><?php echo gettext("Add a comment:"); ?></h3>
    <form id="commentform" action="#" method="post">
    <div><input type="hidden" name="comment" value="1" />
    <input type="hidden" name="remember" value="1" />
    <?php
    printCommentErrors();
    $stored = getCommentStored();
    ?>
    <table border="0">
    <tr>
    <td><label for="name"><?php echo gettext("Name:"); ?></label>
    (<input type="checkbox" name="anon" value="1"<?php if ($stored['anon']) echo " CHECKED"; ?> /> <?php echo gettext("don't publish"); ?>)
    </td>
    <td><input type="text" id="name" name="name" size="20" value="<?php echo $stored['name'];?>" class="inputbox" />
    </td>
    </tr>
    <tr>
    <td><label for="email"><?php echo gettext("E-Mail:"); ?></label></td>
    <td><input type="text" id="email" name="email" size="20" value="<?php echo $stored['email'];?>" class="inputbox" />
    </td>
    </tr>
    <tr>
    <td><label for="website"><?php echo gettext("Site:"); ?></label></td>
    <td><input type="text" id="website" name="website" size="40" value="<?php echo $stored['website'];?>" class="inputbox" /></td>
    </tr>
    <?php if (getOption('Use_Captcha')) {
    $captchaCode=generateCaptcha($img); ?>
    <tr>
    <td><label for="code"><?php echo gettext("Enter Captcha:"); ?>
    <img src=<?php echo "\"$img\"";?> alt="Code" align="bottom"/>
    </label></td>
    <td><input type="text" id="code" name="code" size="20" class="inputbox" /><input type="hidden" name="code_h" value="<?php echo $captchaCode;?>"/></td>
    </tr>
    <?php } ?>
    <tr><td colspan="2"><input type="checkbox" name="private" value="1"<?php if ($stored['private']) echo " CHECKED"; ?> /> <?php echo gettext("Private (don't publish)"); ?></td></tr>
    </table>
    <textarea name="comment" rows="6" cols="40"><?php echo $stored['comment']; ?></textarea>

    <input type="submit" value="<?php echo gettext('Add Comment'); ?>" class="pushbutton" /></div>
    </form>
    </div>
    </div>
    <?php } else { echo gettext('Comments are closed.'); } ?>
    <?php } ?>
    </div>
    <?php } ?>
    </div>

    <div id="credit"><?php printRSSLink('Gallery','','RSS', ' | '); ?> <?php printCustomPageURL(gettext("Archive View"),"archive"); ?> |
    <?php printZenphotoLink(); ?>
    </div>

    <?php if (function_exists('printAdminToolbox')) printAdminToolbox(); ?>

    </body>
    </html>
  • In my theme is just under the image but you can place it anywhere you want the hitcounter to appear.
    In the default theme I'd say paste this between <div> and <div id="narrow"> (line 57-58)

    <div><?php
    $h = getHitcounter();
    if ($h == 1) {
    echo "<p align='center'>".gettext('1 view')."</p>";
    } else {
    echo "<p align='center'>".sprintf(gettext('%u views'),$h)."</p>";
    }
    ?></div>
  • Nice, thank you!
  • Barara, I almost have it...if I could solicit your help once more..

    Here is my image file:

    <?php if (!defined('WEBPATH')) die(); $themeResult = getTheme($zenCSS, $themeColor, 'light'); $firstPageImages = normalizeColumns('2', '6');?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?php zenJavascript(); ?>
    <title><?php echo getBareGalleryTitle(); ?> | <?php echo getBareAlbumTitle();?> | <?php echo getBareImageTitle();?></title>
    <link rel="stylesheet" href="<?php echo $zenCSS ?>" type="text/css" />
    <link rel="stylesheet" href="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.css" type="text/css" />
    <script src="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.js" type="text/javascript"></script>
    <script type="text/javascript">
    function toggleComments() {
    var commentDiv = document.getElementById("comments");
    if (commentDiv.style.display == "block") {
    commentDiv.style.display = "none";
    } else {
    commentDiv.style.display = "block";
    }
    }
    </script>
    <?php printRSSHeaderLink('Gallery',gettext('Gallery RSS')); ?>

    </head>

    <body>

    <div id="main">

    <div id="gallerytitle">
    <div class="imgnav">
    <?php if (hasPrevImage()) { ?>
    <div class="imgprevious">" title="<?php echo gettext("Previous Image"); ?>">« <?php echo gettext("prev"); ?></div>
    <?php } if (hasNextImage()) { ?>
    <div class="imgnext">" title="<?php echo gettext("Next Image"); ?>"><?php echo gettext("next"); ?> »</div>
    <?php } ?>
    </div>
    <h2><span><?php printHomeLink('', ' | '); ?>" title="<?php gettext('Albums Index'); ?>"><?php echo getGalleryTitle();?>
    | <?php printParentBreadcrumb("", " | ", " | "); printAlbumBreadcrumb("", " | "); ?>
    </span> <?php printImageTitle(true); ?>
    </h2>

    </div>

    <!-- The Image -->
    <?php if (!checkForPassword()) { ?>
    <div id="image">
    " title="<?php echo getBareImageTitle();?>">

    <?php
    if (function_exists('printUserSizeImage')) {
    printUserSizeImage(getImageTitle());
    } else {
    printDefaultSizedImage(getImageTitle());
    }
    ?>

    <?php if (function_exists('printUserSizeImage')) printUserSizeSelectior(); ?>
    </div>

    <?php
    $h = getHitcounter();
    if ($h == 1) {
    echo "<p align='center'>".gettext('1 view')."</p>";
    } else {
    echo "<p align='center'>".sprintf(gettext('%u views'),$h)."</p>";
    }
    ?>

    <div id="narrow">
    <?php printImageDesc(true); ?>
    <?php if (function_exists('printSlideShowLink')) printSlideShowLink(gettext('View Slideshow')); ?>
    <hr />
    <?php
    if (getImageEXIFData()) {echo "<div id=\"exif_link\">".gettext("Image Info")."</div>";
    printImageMetadata('', false);
    }
    ?>
    <?php printTags('links', gettext('Tags:').' ', 'taglist', ''); ?>
    <br clear=all />

    <?php if (function_exists('printImageMap')) printImageMap(); ?>

    <?php if (function_exists('printImageRating')) { printImageRating(); }?>

    <?php if (function_exists('printShutterfly')) printShutterfly(); ?>

    <?php if (getOption('Allow_comments')) { ?>
    <div id="comments">
    <?php $num = getCommentCount(); echo ($num == 0) ? "" : ("<h3>".sprintf(gettext('Comments (%u)'), $num)."</h3><hr />"); ?>
    <?php while (next_comment()){ ?>
    <div class="comment">
    <div class="commentmeta">
    <span class="commentauthor"><?php printCommentAuthorLink(); ?></span>
    </div>
    <div class="commentbody">
    <?php echo getCommentBody();?>
    </div>
    <div class="commentdate">
    <?php echo getCommentDateTime();?>
    <?php printEditCommentLink(gettext('Edit'), ' | ', ''); ?>
    </div>
    </div>
    <?php }; ?>

    <?php if (OpenedForComments()) { ?>
    <div class="imgcommentform">
    <!-- If comments are on for this image AND album... -->
    <h3><?php echo gettext("Add a comment:"); ?></h3>
    <form id="commentform" action="#" method="post">
    <div><input type="hidden" name="comment" value="1" />
    <input type="hidden" name="remember" value="1" />
    <?php
    printCommentErrors();
    $stored = getCommentStored();
    ?>
    <table border="0">
    <tr>
    <td><label for="name"><?php echo gettext("Name:"); ?></label>
    (<input type="checkbox" name="anon" value="1"<?php if ($stored['anon']) echo " CHECKED"; ?> /> <?php echo gettext("don't publish"); ?>)
    </td>
    <td><input type="text" id="name" name="name" size="20" value="<?php echo $stored['name'];?>" class="inputbox" />
    </td>
    </tr>
    <tr>
    <td><label for="email"><?php echo gettext("E-Mail:"); ?></label></td>
    <td><input type="text" id="email" name="email" size="20" value="<?php echo $stored['email'];?>" class="inputbox" />
    </td>
    </tr>
    <tr>
    <td><label for="website"><?php echo gettext("Site:"); ?></label></td>
    <td><input type="text" id="website" name="website" size="40" value="<?php echo $stored['website'];?>" class="inputbox" /></td>
    </tr>
    <?php if (getOption('Use_Captcha')) {
    $captchaCode=generateCaptcha($img); ?>
    <tr>
    <td><label for="code"><?php echo gettext("Enter Captcha:"); ?>
    <img src=<?php echo "\"$img\"";?> alt="Code" align="bottom"/>
    </label></td>
    <td><input type="text" id="code" name="code" size="20" class="inputbox" /><input type="hidden" name="code_h" value="<?php echo $captchaCode;?>"/></td>
    </tr>
    <?php } ?>
    <tr><td colspan="2"><input type="checkbox" name="private" value="1"<?php if ($stored['private']) echo " CHECKED"; ?> /> <?php echo gettext("Private (don't publish)"); ?></td></tr>
    </table>
    <textarea name="comment" rows="6" cols="40"><?php echo $stored['comment']; ?></textarea>

    <input type="submit" value="<?php echo gettext('Add Comment'); ?>" class="pushbutton" /></div>
    </form>
    </div>
    </div>
    <?php } else { echo gettext('Comments are closed.'); } ?>
    <?php } ?>
    </div>
    <?php } ?>
    </div>

    <div id="credit"><?php printRSSLink('Gallery','','RSS', ' | '); ?> <?php printCustomPageURL(gettext("Archive View"),"archive"); ?> |
    <?php printZenphotoLink(); ?>
    </div>

    <?php if (function_exists('printAdminToolbox')) printAdminToolbox(); ?>

    </body>
    </html>

    With the hitcounter script you provieded where I have it the counter is aligned left of the page instead of centered under the image. Do you think you could please show me or fix it?

    Thank you very much
Sign In or Register to comment.