0

では、画像タグの下の画像キャプションを右端に揃えるにはどうすればよいでしょうか?

div を使用しようとしましたが、明らかに wp では許可されていません。

どのような代替 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 に答える