This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/source/_posts/2010-10-22-better-photo-gallery-21.md

56 lines
1.7 KiB
Markdown
Raw Normal View History

2015-03-16 21:18:03 +00:00
---
title: Create a Better Photo Gallery in Drupal - Part 2.1
slug: create-better-photo-gallery-drupal-part-21
2015-04-13 11:42:09 +00:00
tags:
2015-06-14 02:27:41 +00:00
- drupal
2015-03-16 21:18:03 +00:00
---
2015-05-03 17:55:38 +00:00
Today, I realised that I hadn't published the code that I used to create the total figures of galleries and photos at the top of the gallery (I said at the end of [Part 2](/blog/create-better-photo-gallery-drupal-part-2/ "Create a Better Photo Gallery in Drupal - Part 2") that I'd include it in [Part 3](/blog/create-better-photo-gallery-drupal-part-3/ "Create a Better Photo Gallery in Drupal - Part 3"), but I forgot). So, here it is:
2015-03-16 21:18:03 +00:00
~~~php
<?php
// Queries the database and returns a list of nids of published galleries.
$galleries = db_query("SELECT nid FROM {node} WHERE type = 'gallery' AND status = 1");
// Resets the number of photos.
$output = 0;
// Prints a list of nids of published galleries.
while($gallery = db_fetch_array($galleries)) {
2015-06-14 02:27:41 +00:00
$gallery_id = $gallery['nid'];
$photos = $photos + db_result(db_query("SELECT COUNT(*) FROM node n, content_type_photo ctp WHERE n.status = 1 AND n.type = 'photo' AND ctp.field_gallery_nid = $gallery_id AND n.nid = ctp.nid"));
2015-03-16 21:18:03 +00:00
}
2015-06-14 02:27:41 +00:00
2015-03-16 21:18:03 +00:00
// Prints the output.
print 'There ';
if($photos == 1) {
2015-06-14 02:27:41 +00:00
print 'is';
2015-03-16 21:18:03 +00:00
}
else {
2015-06-14 02:27:41 +00:00
print 'are';
2015-03-16 21:18:03 +00:00
}
print ' currently ';
print $photos . ' ';
if($photos == 1) {
2015-06-14 02:27:41 +00:00
print 'photo';
2015-03-16 21:18:03 +00:00
}
else {
2015-06-14 02:27:41 +00:00
print 'photos';
2015-03-16 21:18:03 +00:00
}
print ' in ';
2015-06-14 02:27:41 +00:00
2015-03-16 21:18:03 +00:00
// Counts the number of published galleries on the site.
$galleries = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE TYPE = 'gallery' AND STATUS = 1"));
2015-06-14 02:27:41 +00:00
2015-03-16 21:18:03 +00:00
// Prints the number of published galleries.
print $galleries;
if ($galleries == 1) {
2015-06-14 02:27:41 +00:00
print ' gallery';
2015-03-16 21:18:03 +00:00
}
else {
2015-06-14 02:27:41 +00:00
print ' galleries';
2015-03-16 21:18:03 +00:00
}
print '.';
?>
~~~
2015-06-14 02:27:41 +00:00
It was applied to the view as a header which had the input format set to PHP code.