Thread Starter
nblauw
(@nblauw)
Posted on my mobile, sorry for that!
You can count the gallery images inside the loop with this:
<?php
$item_count = '';
$gallery = do_shortcode( $post->post_content );
if (preg_match_all( '/class=\'gallery-item\'\>/', $gallery, $matches ) ) {
$item_count = count($matches[0]);
}
?>
Then you can add the count to your title like so:
<?php echo get_the_title() . ' ' . $item_count; ?>
This only counts the images in galleries, not the attached images (inserted in posts).
btw:
consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.
Thread Starter
nblauw
(@nblauw)
Thank you very much!
Where do I place the codes?
Thanks for the quick response!
Or put this in your themes functions.php and use the shortcode after your title in the editor “Foto’s ([gallery_count])”:
add_filter( 'the_title', 'do_shortcode' );
add_shortcode( 'gallery_count', 'add_gallery_count' );
function add_gallery_count( $atts ) {
global $post;
if(isset( $post->post_content)) {
$gallery = do_shortcode( $post->post_content );
if (preg_match_all( '/class=\'gallery-item\'\>/', $gallery, $matches ) ) {
$item_count = count( $matches[0] );
return $item_count;
}
}
}
Where do I place the codes?
Use the last code example and put in your theme’s functions.php or create a plugin with the code with this plugin:
http://wordpress.org/extend/plugins/pluginception/
Thread Starter
nblauw
(@nblauw)
Thanks!
Same question for the DMSquestbook plugin on my site,
How get the number of message in my questbook?
Thanks again for your help!
It’s best to create a new topic for that in the plugin support section: http://wordpress.org/support/plugin/dmsguestbook#postform
Thread Starter
nblauw
(@nblauw)
I inserted the code in functions.php.
Now Only in the page editor the number 6 shows up. ( like fotoalbum (6)) (Dashboard).
When i go to my website it shows up like: fotoalbum ()
(Bartbroersen.nl)
How come?
P.S.
I edited functions.PHP of my theme HUM
Do you have a gallery of photos in that post? Can we get a link to it?
http://codex.wordpress.org/The_WordPress_Gallery
Thread Starter
nblauw
(@nblauw)
Its a page with a gallery on it
http://bartbroersen.site50.net/?page_id=30
When you on the page you See (6), But when on the homepage you See ().
Thanks for helping!
I can’t find it on the home page?
Thread Starter
nblauw
(@nblauw)
In the sidebar left on the homepage in the menu you See ” fotoalbum ()”, when you click on it you go to the gallery. Look again at the menu and you See “fotoalbum (6)”
Ah, my screen size is to small to see it. This code only works within the loop. Try adding this to your theme’s functions.php file:
add_filter('wp_nav_items', 'do_shortcode');
add_filter( 'wp_title', 'do_shortcode' );
add_filter( 'wp_list_pages', 'do_shortcode' );
Thread Starter
nblauw
(@nblauw)
Added the 3 lines to functions.php from my HUM theme, but it is still not working.
Thread Starter
nblauw
(@nblauw)
I can see it on my dashboard (admin side of the website), i can see it on the page where the gallery is, but on the homepage i cant see it.