簡體   English   中英

WordPress:如何添加與圖像邊緣右對齊的標題

[英]Wordpress: How to add a caption right-aligned to the edge of the image

那么,如何將圖像標簽下的圖像標題與右邊緣對齊?

使用div嘗試過,但顯然在wp中是不允許的。

我需要使用哪些替代的CSS /標簽?

這行不通嗎?

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

我想出了一種根據字幕指定對齊方式的方法。

基本上,我從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>';
}

希望能對某人有所幫助!

在Wordpress社區網站論壇上也被問到 ,沒有回應,因此推測這不是2.2.1的功能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM