Php Wordpress小部件作为div

Php Wordpress小部件作为div,php,html,wordpress,widget,Php,Html,Wordpress,Widget,我创建了以“Hello World!”为内容的简单小部件: public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; //if title is present if ( ! empty( $title ) ) echo $args['b

我创建了以“Hello World!”为内容的简单小部件:

    public function widget( $args, $instance ) {
    $title = apply_filters( 'widget_title', $instance['title'] );
    echo $args['before_widget'];
    //if title is present
    if ( ! empty( $title ) )
    echo $args['before_title'] . $title . $args['after_title'];
    //output
    echo __( 'Hello World!', 'hstngr_widget_domain' );
    echo $args['after_widget']; }
但我需要将其实现为div。如果需要,有一个代码:

<div class='col-sm-12 col-md-8' style="padding-bottom: 15px;">
    <div class="more-equities-research-at-tipranks">
        <h3>More <span class="equities-name"><?php echo $company_ticker ?></span> Research at TipRanks</h3>
        <div class="equities-icons-links">
            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>" class="equities-link margin-b-15">
                <span class="equities-icons analyst-ratings"></span>analyst ratings
            </a>

            <a target="_blank" href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-predictions" class="equities-link margin-b-15">
                <span class="equities-icons blogger-opinions"></span>blogger opinions
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-news" class="equities-link margin-b-15">
                <span class="equities-icons news-sentiment"></span>news sentiment
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-charts" class="equities-link margin-b-15">
                <span class="equities-icons stats-charts"></span>stats charts
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/investor-sentiment" class="equities-link">
                <span class="equities-icons investor-sentiment"></span>investor sentiment
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/insider-trading" class="equities-link">
                <span class="equities-icons insider-activity"></span>insider activity
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/hedge-funds" class="equities-link">
                <span class="equities-icons hedge-funds"></span>hedge funds
            </a>
        </div>
    </div>
</div>

TipRanks的更多研究
但问题是我不知道如何通过“echo”输出这个div。这是真的吗?如何做到这一点?
对不起我的英语

你可以这样使用它

echo "<div class='someclass'>Hello World!</div>";
echo“你好,世界!”;
只要确保您有使用不同引号的类或id

试试这个:

echo $args['before_title'] . $title . $args['after_title'];
?>
<div class='col-sm-12 col-md-8' style="padding-bottom: 15px;">
    <div class="more-equities-research-at-tipranks">
        <h3>More <span class="equities-name"><?php echo $company_ticker ?></span> Research at TipRanks</h3>
        <div class="equities-icons-links">
            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>" class="equities-link margin-b-15">
                <span class="equities-icons analyst-ratings"></span>analyst ratings
            </a>

            <a target="_blank" href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-predictions" class="equities-link margin-b-15">
                <span class="equities-icons blogger-opinions"></span>blogger opinions
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-news" class="equities-link margin-b-15">
                <span class="equities-icons news-sentiment"></span>news sentiment
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/stock-charts" class="equities-link margin-b-15">
                <span class="equities-icons stats-charts"></span>stats charts
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/investor-sentiment" class="equities-link">
                <span class="equities-icons investor-sentiment"></span>investor sentiment
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/insider-trading" class="equities-link">
                <span class="equities-icons insider-activity"></span>insider activity
            </a>

            <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker; ?>/hedge-funds" class="equities-link">
                <span class="equities-icons hedge-funds"></span>hedge funds
            </a>
        </div>
    </div>
</div>
<?php
echo $args['after_widget']; }
echo$args['before_title']$标题$args[“在标题之后];
?>
TipRanks的更多研究

有两种方法可以处理用PHP输出大量HTML。首先,您可以退出PHP:

class Foo_Widget extends WP_Widget {
    public function widget( $args, $instance ){
        echo $args['before_widget'];
            if( $title = apply_filters( 'widget_title', $instance['title'] ) )
                echo $args['before_title'] . $title . $args['after_title']; ?>

            <div class="col-sm-12 col-md-8" style="padding-bottom: 15px;">
                <!-- Rest of the code here -->
            </div>
        <?php echo $args['after_widget'];
    }
}
class Foo\u小部件扩展WP\u小部件{
公共函数小部件($args,$instance){
echo$args['before_widget'];
如果($title=apply_过滤器('widget_title',$instance['title']))
echo$args['before_title']。$title.$args['before_title'];?>
TipRanks的更多研究
class Foo_Widget extends WP_Widget {
    public function widget( $args, $instance ){
        echo $args['before_widget'];
            if( $title = apply_filters( 'widget_title', $instance['title'] ) )
                echo $args['before_title'] . $title . $args['after_title'];

            ob_start(); ?>
                <div class="col-sm-12 col-md-8" style="padding-bottom: 15px;">
                    <!-- Rest of the code here -->
                </div>
        <?php echo ob_get_clean();
        echo $args['after_widget'];
    }
}
class Foo_Widget extends WP_Widget {
    public function widget( $args, $instance ){
        echo $args['before_widget'];
            if( $title = apply_filters( 'widget_title', $instance['title'] ) )
                echo $args['before_title'] . $title . $args['after_title'];

            echo '<div class="col-sm-12 col-md-8" style="padding-bottom: 15px;">
                <!-- Rest of the code here -->
            </div>';
        echo $args['after_widget'];
    }
}
class Foo_Widget extends WP_Widget {
    public function widget( $args, $instance ){
        echo $args['before_widget'];
            if( $title = apply_filters( 'widget_title', $instance['title'] ) )
                echo $args['before_title'] . $title . $args['after_title'];

            $html = '<div class="col-sm-12 col-md-8" style="padding-bottom: 15px;">';
                $html .= '<!-- Rest of the code here -->';
            $html .= '</div>';

            echo $html;
        echo $args['after_widget'];
    }
}
class Foo_Widget extends WP_Widget {
    public function widget( $args, $instance ){
        echo $args['before_widget'];
            if( $title = apply_filters( 'widget_title', $instance['title'] ) )
                echo $args['before_title'] . $title . $args['after_title']; ?>

            <div class="col-sm-12 col-md-8" style="padding-bottom: 15px;">
                <div class="more-equities-research-at-tipranks">
                    <h3>More <span class="equities-name"><?php echo $company_ticker ?></span> Research at TipRanks</h3>
                    <div class="equities-icons-links">
                        <?php
                            $array = array(
                                'analyst ratings'    => array( 'link', 'margin-b-15' ),
                                'blogger opinions'   => array( '/stock-predictions', 'margin-b-15' ),
                                'news sentiment'     => array( '/stock-news', 'margin-b-15' ),
                                'stats charts'       => array( '/stock-charts', 'margin-b-15' ),
                                'investor sentiment' => array( '/investor-sentiment', '' ),
                                'insider activity'   => array( '/insider-trading', '' ),
                                'hedge funds'        => array( '/hedge-funds', '' ),
                            );

                            foreach( $array as $item => $atts ){ ?>
                                <a target="_blank"  href="https://www.tipranks.com/stocks/<?php echo $company_ticker.$atts[0]; ?>" class="equities-link <?php echo $atts[1]; ?>">
                                    <span class="equities-icons <?php echo sanitize_title_with_dashes( $item ); ?>"></span><?php echo $item; ?>
                                </a>
                            <?php }
                        ?>
                    </div>
                </div>
            </div>
        <?php echo $args['after_widget'];
    }
}