有没有办法在存档页面上的帖子“循环”中添加“社交共享”按钮,以便共享的 URL 是帖子的 URL,而不是存档的 URL?

问题描述 投票:0回答:1

我创建了一个帖子循环来在存档页面上显示我的所有帖子,我想向这些循环添加一个社交共享按钮,以便用户可以从存档页面共享文章,而无需打开帖子然后共享它。

我尝试直接在循环中添加社交共享按钮,以为它会拉出帖子 URL,但事实并非如此;t

wordpress loops post dynamic
1个回答
0
投票

为此,我建议您安装AddToAny Share Buttons插件,它为各种社交网络提供可自定义的共享按钮。安装并激活后,我们可以在循环中使用

ADDTOANY_SHARE_SAVE_KIT
函数来显示社交共享图标。

您可以使用给定的代码循环显示带有社交分享图标的帖子。

<?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
            <header class="entry-header" >
                <h2 class="entry-title" >
                    <a href="<?php the_permalink(); ?>">
                        <?php the_title(); ?>
                    </a>
                </h2>
            </header>
            <!-- .entry-header -->
            
            <div class="entry-content">
                <?php the_excerpt(); ?>
            </div>
            <!-- .entry-content -->

            <footer class="entry-footer">
                <div class="social-share-buttons">
                    <?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) {
                        ADDTOANY_SHARE_SAVE_KIT( array(
                            'buttons' => array(
                                'facebook', 'twitter', 'linkedin', 'pinterest', 'email', 'share_more'
                            ),
                            'button_style' => 'icon',
                            'title' => get_the_title(),
                            'linkname' => get_the_permalink(),
                        ) );
                    } ?>
                </div>
            </footer>
            <!-- .entry-footer -->
        </article>
        <!-- #post-<?php the_ID(); ?> -->
    <?php endwhile; ?>
    
    <?php the_posts_pagination(); ?>
    
<?php else : ?>
    <p><?php esc_html_e( 'No posts found' ); ?></p>
<?php endif; ?>
© www.soinside.com 2019 - 2024. All rights reserved.