自定义博客模块,用于将html输出为纯文本

时间:2016-07-09 21:28:04

标签: php wordpress

$emailmessage = wordwrap($emailmessage, 100, "\r\n");

$emailmessage = '<html><body>';
$emailmessage .= '<img src="imageurl" alt="Logo" />';
$emailmessage .= '<table rules="all" border="1" style="border-color: #666;" cellpadding="10">';
$emailmessage .= "<tr style='background: #eee;'><th colspan='2'><strong>" . $commentSubject ."</strong></th></tr>";
$emailmessage .= "<tr><td>" . $commentmessage . "</td></tr>";
$emailmessage .= "<tr><td><b>Ticket #: </b>" . $ticketid . "</td></tr>";
$emailmessage .= "</table>";
$emailmessage .= "</body></html>";
// Send Mail By PHP Mail Function
if (mail($to, $subject, $emailmessage, $headers)) {
    $message = "Your mail has been sent successfully!";
} 
else {
    $message = "Failed to send email, try again.";
}

我正在创建一个自定义divi模块,以便为博客帖子模块添加一些无法用html / css完成的功能。

<?php
if ( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments ) {
    printf( '<p class="post-meta">%1$s %2$s %3$s %4$s %5$s %6$s %7$s</p>',
        (
            'on' === $show_author
                ? et_get_safe_localization( sprintf( __( 'by %s', 'et_builder' ), '<span class="author vcard">' .  et_pb_get_the_author_posts_link() . '</span>' ) )
                : ''
        ),
        (
            ( 'on' === $show_author && 'on' === $show_date )
                ? '  '
                : ''
        ),
        (
            'on' === $show_date
                ? et_get_safe_localization( sprintf( __( '%s', 'et_builder' ), '<span class="published">' . esc_html( get_the_date( $meta_date ) ) . '</span>' ) )
                : ''
        ),
        (
            (( 'on' === $show_author || 'on' === $show_date ) && 'on' === $show_categories)
                ? '  '
                : ''
        ),
        (
            'on' === $show_categories
                ? get_the_category_list(', ')
                : ''
        ),
        (
            (( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories ) && 'on' === $show_comments)
                ? '  '
                : ''
        ),
        (
            'on' === $show_comments
                ? sprintf( esc_html( _nx( '1 Comment', '<span class="comments">%s Comments</span>', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) )
                : ''
        )
    );
}

echo '<div class="post-content">';

$post_content = get_the_content();

// do not display the content if it contains Blog, Post Slider, Fullwidth Post Slider, or Portfolio modules to avoid infinite loops
if ( ! has_shortcode( $post_content, 'et_pb_blog' ) && ! has_shortcode( $post_content, 'et_pb_portfolio' ) && ! has_shortcode( $post_content, 'et_pb_post_slider' ) && ! has_shortcode( $post_content, 'et_pb_fullwidth_post_slider' ) ) {
    if ( 'on' === $show_content ) {
        global $more;

        // page builder doesn't support more tag, so display the_content() in case of post made with page builder
        if ( et_pb_is_pagebuilder_used( get_the_ID() ) ) {
            $more = 1;
            the_content();
        } else {
            $more = null;
            the_content( esc_html__( 'read more...', 'et_builder' ) );
        }
    } else {
        if ( has_excerpt() ) {
            the_excerpt();
        } else {
            echo wpautop( truncate_post( 270, false ) );
        }
    }
} else if ( has_excerpt() ) {
    the_excerpt();
}

if ( 'on' !== $show_content ) {
    $more = 'on' == $show_more ? sprintf( ' <a href="%1$s" class="more-link" >%2$s</a>' , esc_url( get_permalink() ), esc_html__( 'read more', 'et_builder' ) )  : '';
    echo $more;
}

echo '</div>';
?>

这一行输出'on' === $show_comments ? sprintf( esc_html( _nx( '1 Comment', '<span class="comments">%s Comments</span>', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) ) : '' 作为原始文本,我需要将它包装在一个类中。我将如何格式化以获得所需的结果?

1 个答案:

答案 0 :(得分:0)

您好我不知道是否为时已晚或您已设法解决问题。但是对于那些面临同样问题的人来说,只需使用完整标签而不是我,它就是wp-content / themes / Divi 3 2 / includes / builder / main-modules.php第12284行。