Hello, I am trying to get Multiple post Thumbnails to work, it requires I add this to functions.php, or now, extras.php, but not sure the namespace to give, since its in the plugins directory
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(
array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => 'post'
)
);
}
this of course breaks the site. How do I fix?
Give the namespaces section a read here: https://roots.io/upping-php-requirements-in-your-wordpress-themes-and-plugins/
But I would assume that since you are in a file with a namespace declared, you probably have to use the class_exists function like this: if (class_exists('\\MultiPostThumbnails')) {
Basically, it’s probably checking if the class exists in the current namespace, but adding \
to any class makes it look in the global namespace.
I’ve studied up some more on it and things are working great! For example, I added this to extras
// limit excerpt by character count, not word count
function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = $excerpt.'';
return $excerpt;
}
then on my index.php page, I used it like this:
at the top of the page, put: (to denote that I’m namespacing to extras:
<?php use Roots\Sage\Extras; ?>
then called my function:
<?= Extras\get_excerpt(122); ?>
and it worked! thanks!
@mikeylythcott did you ever end up getting the Multiple Post Thumbnails to work? If so, how’d you do it?
Nope, only if i put in in functions.php. Namespacing it as suggested by Kale Johnson killed the errors, but the plugin’s functionality still never actually displayed in the admin, unless I put it in functions.php