0

那么如何将图像标签下的图像标题与其右侧边缘对齐?

尝试使用 div 但显然这在 wp.xml 中是不允许的。

我需要使用哪些替代 CSS/标签?

4

3 回答 3

1

这不起作用吗?

.wp-caption p.wp-caption-text { text-align:right; }

于 2009-11-28T15:50:03.953 回答
1

我想出了一种方法来指定每个字幕的对齐方式。

基本上,我从 media.php 复制了标题短代码,并将其制成我自己的自定义函数,该函数接受“captionalign”参数。

要使用,请将以下代码粘贴到主题的“function.php”文件中 - 这将允许您在标题标签中指定一个名为 captionalign 的选项。通过将其设置为右、左或居中,您可以指定每个标题的文本对齐方式。省略该属性将使标题默认为您的默认对齐方式。

使用中的一个例子:

[caption align="aligncenter" width="300" caption="My caption" captionalign="right"]
<a href="http://www.myawesomeblog.com/wp-content/uploads/2010/05/image.jpg">
<img title="My image" src="http://www.myawesomeblog.com/wp-content/uploads/2010/05/image.jpg-300x216.jpg" alt="My image" width="300" height="216" />
</a>
[/caption]

这是功能:

add_shortcode('wp_caption', 'custom_img_caption_shortcode');
add_shortcode('caption', 'custom_img_caption_shortcode');

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is 'img_caption_shortcode' and passes an empty string, the attr
 * parameter and the content parameter values.
 *
 * The supported attributes for the shortcode are 'id', 'align', 'width', and
 * 'caption'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function custom_img_caption_shortcode($attr, $content = null) {

// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
    return $output;

extract(shortcode_atts(array(
    'id'    => '',
    'align' => 'alignnone',
    'width' => '',
    'caption' => '',
    'captionalign' => ''
), $attr));

if ( 1 > (int) $width || empty($caption) )
    return $content;

if ( $id ) $id = 'id="' . esc_attr($id) . '" ';

return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text" style="text-align:' . $captionalign . '">' . $caption . '</p></div>';
}

希望对某人有所帮助!

于 2010-05-19T20:22:51.887 回答
0

在 Wordpress 社区网站论坛上也被问到,没有回应,所以大概这不是 2.2.1 的功能

于 2009-12-10T10:50:46.543 回答