我怎样才能正确地将这个html放在我的PHP脚本中

时间:2014-07-22 22:09:27

标签: php html wordpress

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

    <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文件中,这是:

        <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 -->

-----戴夫这是我尝试你所问的方式:

    <?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,这是我的尝试:

    <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 -->

2 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情(根本不优雅)吗?

取代:

<?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>'
            ),

使用:

$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>'
            ),

答案 1 :(得分:0)

将代码放在[YOUR CODE HERE]所在的位置。如果你想要懒惰,那就把它放在那里。请注意,通过在其前面放置\来逃避代码中的单引号非常重要

<?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( '[entry-author] / [entry-published]', 'fearless' ) . '[YOUR CODE HERE]</div>' ); ?>

你可能想以这种方式逃避单引号:

$str = [YOUR CODE];
string addslashes ( string $str );

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