首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确地将此html放入PHP脚本中

如何正确地将此html放入PHP脚本中
EN

Stack Overflow用户
提问于 2014-07-23 06:09:27
回答 2查看 341关注 0票数 1

我想将我的打印友好按钮添加到我标题下的所有帖子中。这是按钮的HTML:

代码语言:javascript
复制
    <script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = 'right';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/>
    </a>

现在,我放在我的侧边栏中生成的HTML打印友好代码中的示例可以在这里看到:

http://iamdentistry.com/archive/dentistry/about-dental-night-guards/

我不知道怎么把这个按钮移到我想要的地方。我想把它放在与最右边的帖子标题下的Leave A Response按钮相同的一行。

我问了主题的作者,他们告诉我的是,我需要将代码添加到我的主题的content.php文件中,即:

代码语言:javascript
复制
        <article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">

<?php if ( is_singular( get_post_type() ) ) : ?>

    <?php
    $format = get_post_format();
    get_template_part( 'post-header', $format );
    ?>

    <header class="entry-header">
        <?php if (
                fearless_get_option( 'singular_featured_image_enabled' )
                && 'audio' != $format
                && 'gallery' != $format
                && 'video' != $format
            ) {
                fearless_post_thumbnail();
            }
        ?>

        <h1 class="entry-title"><?php single_post_title(); ?></h1>
        <?php
        printf(
            apply_atomic_shortcode(
                'entry_byline',
                '<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . '</div>'
            ),
            sprintf(
                _n(
                    '1 View',
                    '%1$s Views',
                    get_post_meta( get_the_ID(), 'Views', true ),
                    'fearless'
                ),
                get_post_meta( get_the_ID(), 'Views', true )
            )
        );
        ?>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php if ( is_singular( 'post' ) ) get_template_part( 'review-box' ); ?>
        <?php the_content(); ?>
        <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
    </div><!-- .entry-content -->

    <footer class="entry-footer">
        <?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms before="Posted in " taxonomy="category"] [entry-terms before="| Tagged "]', 'fearless' ) . '</div>' ); ?>
    </footer><!-- .entry-footer -->

<?php else : ?>

    <?php global $fearless_blogroll_layout; ?>

    <?php fearless_post_thumbnail( $fearless_blogroll_layout['thumbnail_size'] ); ?>

    <header class="entry-header">
        <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '">', '</a></h2>' ); ?>
        <?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '</div>' ); ?>
    </header><!-- .entry-header -->

    <?php if ( $fearless_blogroll_layout['excerpt_length'] ) : ?>
        <div class="entry-summary">
            <?php echo fearless_get_the_excerpt( $fearless_blogroll_layout['excerpt_length'] ); ?>
            <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
        </div><!-- .entry-summary -->
    <?php endif; ?>

    <?php if ( '1col-thumb' != $fearless_blogroll_layout['style'] ) : ?>
        <p class="more-link-wrapper"><a href="<?php the_permalink(); ?>" class="read-more button"><?php _e( 'Read More &raquo;', 'fearless' ); ?></a></p>
    <?php endif; ?>

<?php endif; ?>

    </article><!-- .hentry -->

- Dave这就是我如何尝试你所问的:

代码语言:javascript
复制
    <?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '<script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = 'right';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/></a></div>' ); 
    ?>

-Christopher Pecoraro,这是我的尝试:

代码语言:javascript
复制
    <article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">

<?php if ( is_singular( get_post_type() ) ) : ?>

    <?php
    $format = get_post_format();
    get_template_part( 'post-header', $format );
    ?>

    <header class="entry-header">
        <?php if (
                fearless_get_option( 'singular_featured_image_enabled' )
                && 'audio' != $format
                && 'gallery' != $format
                && 'video' != $format
            ) {
                fearless_post_thumbnail();
            }
        ?>

        <h1 class="entry-title"><?php single_post_title(); ?></h1>
        $link_text = '<script>var pfHeaderImgUrl = \'\';var pfHeaderTagline = \'\';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = \'right\';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = \'\';var pfBtVersion=\'1\';(function(){var js, pf;pf = document.createElement(\'script\');pf.type = \'text/javascript\';if(\'https:\' == document.location.protocol){js=\'https://pf-cdn.printfriendly.com/ssl/main.js\'}else{js=\'http://cdn.printfriendly.com/printfriendly.js\'}pf.src=js;document.getElementsByTagName(\'head\')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/></a>';
    printf(
        apply_atomic_shortcode(
            'entry_byline',
            '<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . $link_text . '</div>'
        ),
            sprintf(
                _n(
                    '1 View',
                    '%1$s Views',
                    get_post_meta( get_the_ID(), 'Views', true ),
                    'fearless'
                ),
                get_post_meta( get_the_ID(), 'Views', true )
            )
        );
        ?>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php if ( is_singular( 'post' ) ) get_template_part( 'review-box' ); ?>
        <?php the_content(); ?>
        <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
    </div><!-- .entry-content -->

    <footer class="entry-footer">
        <?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms before="Posted in " taxonomy="category"] [entry-terms before="| Tagged "]', 'fearless' ) . '</div>' ); ?>
    </footer><!-- .entry-footer -->

<?php else : ?>

    <?php global $fearless_blogroll_layout; ?>

    <?php fearless_post_thumbnail( $fearless_blogroll_layout['thumbnail_size'] ); ?>

    <header class="entry-header">
        <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '">', '</a></h2>' ); ?>
        <?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '</div>' ); ?>
    </header><!-- .entry-header -->

    <?php if ( $fearless_blogroll_layout['excerpt_length'] ) : ?>
        <div class="entry-summary">
            <?php echo fearless_get_the_excerpt( $fearless_blogroll_layout['excerpt_length'] ); ?>
            <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'fearless' ) . '</span>', 'after' => '</p>' ) ); ?>
        </div><!-- .entry-summary -->
    <?php endif; ?>

    <?php if ( '1col-thumb' != $fearless_blogroll_layout['style'] ) : ?>
        <p class="more-link-wrapper"><a href="<?php the_permalink(); ?>" class="read-more button"><?php _e( 'Read More &raquo;', 'fearless' ); ?></a></p>
    <?php endif; ?>

<?php endif; ?>

    </article><!-- .hentry -->
EN

回答 2

Stack Overflow用户

发布于 2014-07-23 06:22:30

你能试试这样的东西(一点都不优雅)吗?

替换:

代码语言:javascript
复制
<?php
        printf(
            apply_atomic_shortcode(
                'entry_byline',
                '<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . '</div>'
            ),

通过以下方式:

代码语言:javascript
复制
$link_text = '<script>var pfHeaderImgUrl = \'\';var pfHeaderTagline = \'\';var pfdisableClickToDel = 0;var pfHideImages = 0;var pfImageDisplayStyle = \'right\';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 0;var pfCustomCSS = \'\';var pfBtVersion=\'1\';(function(){var js, pf;pf = document.createElement(\'script\');pf.type = \'text/javascript\';if(\'https:\' == document.location.protocol){js=\'https://pf-cdn.printfriendly.com/ssl/main.js\'}else{js=\'http://cdn.printfriendly.com/printfriendly.js\'}pf.src=js;document.getElementsByTagName(\'head\')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;-webkit-box-shadow:none;box-shadow:none;" src="http://cdn.printfriendly.com/button-print-grnw20.png" alt="Print Friendly and PDF"/></a>';
        printf(
            apply_atomic_shortcode(
                'entry_byline',
                '<div class="entry-byline">' . __( 'Posted by [entry-author] on [entry-published] in [entry-terms taxonomy="category"] | %1$s [entry-comments-link before=" | "]', 'fearless' ) . $link_text . '</div>'
            ),
票数 0
EN

Stack Overflow用户

发布于 2014-07-23 06:25:41

将您的代码放在显示为[YOUR CODE HERE]的位置。如果你想变得懒惰,就把它放在那里。请注意,通过在代码中的单引号前面放置一个\来转义它们,这一点非常重要

代码语言:javascript
复制
<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '[YOUR CODE HERE]</div>' ); ?>

您可能希望这样转义单引号:

代码语言:javascript
复制
$str = [YOUR CODE];
string addslashes ( string $str );

然后将$str放在类似...'fearless' ) . $str . '</div>'的代码中,您也可以将所有单引号替换为双引号。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24898713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档