我在运行这个插件时遇到了一些问题,但即使在阅读了过去的条目之后,也没能成功运行它。如果您能看看代码是否正确,我将不胜感激。
函数中的代码。php:
\'// Add secondary thumbnail (featured image) in posts */
if (class_exists(\'MultiPostThumbnails\')) {
new MultiPostThumbnails(array (
\'label\' => \'Secondary Image\',
\'id\' => \'secondary-image\',
\'post_type\' => \'post\' )
);
new MultiPostThumbnails(array(
\'label\' => \'Tertiary Image\',
\'id\' => \'tertiary-image\', )
);
new MultiPostThumbnails(array(
\'label\' => \'Quaternary Image\',
\'id\' => \'quaternary-image\', )
);
}
add_image_size(\'post-secondary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-tertiary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-quaternary-image-thumbnail\', 176, 58, true);\'
相关模板中的代码(我已经发布了整个模板代码,因为我认为您需要完整查看):
<?php
/*
Template Name: Home
*/
?>
<?php get_header(); ?>
<div id=\'main-content\'>
<h2>What We Do</h2>
<ul id="we-do">
<?php query_posts("posts_per_page=1&post_type=page&page_id=168");
the_post (); ?>
<!--If you want to refer to the child of parent page, use "post_parent=" -->
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php if (class_exists(\'MultiPostThumbnails\')
&& MultiPostThumbnails::has_post_thumbnail(\'post\', \'secondary-image\')) :
MultiPostThumbnails::the_post_thumbnail(\'post\', \'secondary-image\'); endif; ?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
<?php query_posts("posts_per_page=1&post_type=page&page_id=236"); the_post(); ?>
<li>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<?php if (class_exists(\'MultiPostThumbnails\')
&& MultiPostThumbnails::has_post_thumbnail(\'post\', \'tertiary-image\')) :
MultiPostThumbnails::the_post_thumbnail(\'post\', \'tertiary-image\'); endif; ?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
<?php query_posts("posts_per_page=1&post_type=page&page_id=240"); the_post(); ?>
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php if (class_exists(\'MultiPostThumbnails\')
&& MultiPostThumbnails::has_post_thumbnail(\'post\', \'quaternary-image\')) :
MultiPostThumbnails::the_post_thumbnail(\'post\', \'quaternary-image\'); endif; ?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
</ul>
</div><!--END main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
我还想对图像应用一个类,但不确定将数组放置在何处。
可能需要注意的是,我也在运行同样注册在函数模板中的特色图像功能。
SO网友:Jeremy Jared
下面是使用您提供的代码的完整示例:
用于您的功能。php文件:
<?php
// Add secondary thumbnail (featured image) in posts */
if (class_exists(\'MultiPostThumbnails\')) {
new MultiPostThumbnails(array (
\'label\' => \'Secondary Image\',
\'id\' => \'secondary-image\',
\'post_type\' => \'post\' )
);
new MultiPostThumbnails(array(
\'label\' => \'Quaternary Image\',
\'id\' => \'quaternary-image\', )
);
new MultiPostThumbnails(array(
\'label\' => \'Tertiary Image\',
\'id\' => \'tertiary-image\', )
);
}
add_image_size(\'post-secondary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-tertiary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-quaternary-image-thumbnail\', 176, 58, true);
?>
对于您的页面模板:
<?php
/*
Template Name: Home
*/
?>
<?php get_header(); ?>
<div id=\'main-content\'>
<h2>What We Do</h2>
<ul id="we-do">
<?php
query_posts("posts_per_page=1&post_type=page&page_id=168");
the_post (); ?>
<!--If you want to refer to the child of parent page, use "post_parent=" -->
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php
MultiPostThumbnails::the_post_thumbnail(\'post\', \'secondary-image\', NULL, \'post-secondary-image-thumbnail\');
?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
<?php
query_posts("posts_per_page=1&post_type=page&page_id=236");
the_post();
?>
<li>
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
<?php
MultiPostThumbnails::the_post_thumbnail(\'post\', \'quaternary-image\', NULL, \'post-quaternary-image-thumbnail\');
?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
<?php query_posts("posts_per_page=1&post_type=page&page_id=240"); the_post(); ?>
<li>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<?php
MultiPostThumbnails::the_post_thumbnail(\'post\', \'tertiary-image\', NULL, \'post-tertiary-image-thumbnail\');
?>
<a href="<?php the_permalink(); ?>" class="button">View More</a>
</li>
</ul>
</div><!--END main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
SO网友:Jeremy Jared
要使代码正常工作,需要在函数中将代码更改为此。php文件:
<?php
// Add secondary thumbnail (featured image) in posts */
if (class_exists(\'MultiPostThumbnails\')) {
new MultiPostThumbnails(array (
\'label\' => \'Secondary Image\',
\'id\' => \'secondary-image\',
\'post_type\' => \'post\' )
);
new MultiPostThumbnails(array(
\'label\' => \'Quaternary Image\',
\'id\' => \'quaternary-image\', )
);
new MultiPostThumbnails(array(
\'label\' => \'Tertiary Image\',
\'id\' => \'tertiary-image\', )
);
}
add_image_size(\'post-secondary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-tertiary-image-thumbnail\', 176, 58, true);
add_image_size(\'post-quaternary-image-thumbnail\', 176, 58, true);
?>
Then to use the code in the template you would use this:
<?php
MultiPostThumbnails::the_post_thumbnail(\'post\', \'secondary-image\', NULL, \'post-secondary-image-thumbnail\');
?>
缩略图将自动添加以下类别:
.attachment-post-secondary-image-thumbnail
这将随着您注册的每个附加大小而更改。它将具有您在函数中指定的图像大小名称的类。php文件。