首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >摘录下的社交分享

摘录下的社交分享
EN

Stack Overflow用户
提问于 2014-07-30 18:53:41
回答 1查看 790关注 0票数 0

请告诉我,有没有插件可以在wordpress帖子摘录下放置社交分享按钮?喜欢下面的网站吗?

http://spiritual-quotes.org/

我在这个网站上看到了别人的回复:

您可以使用一个名为Share Button的WordPress插件来实现此目的。一旦安装,激活并选择你想要添加的图标。将以下内容添加到包含摘录的页面(就在调用摘录之后)。

代码语言:javascript
复制
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>

代码应该类似于:

代码语言:javascript
复制
<?php the_excerpt(); ?>
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?    >

它可能会有所不同,这取决于你如何做摘录。

我使用的是瓦伦蒂主题http://valenti.cubellthemes.com/tag/beats/

我只需要知道我需要在哪里跳过上面的代码才能让它工作。

希望你能帮上忙

谢谢

嗨,这是archive.php中的代码

代码语言:javascript
复制
<?php
        get_header();
        $cb_global_color = ot_get_option('cb_base_color', '#eb9812');
        $cb_theme_style = ot_get_option('cb_theme_style', 'cb_boxed');
?>

<div class="cb-cat-header<?php if ($cb_theme_style == 'cb_boxed') echo ' wrap'; ?>"       style="border-bottom-color:<?php echo $cb_global_color; ?>;">
 <?php if (is_day()) { ?>
        <h1 id="cb-cat-title">
            <span><?php _e("Daily Archives", "cubell"); ?> <i class="fa fa-long-arrow-right"></i></span> <?php the_time(get_option('date_format')); ?>
        </h1>

    <?php } elseif (is_month()) { ?>
        <h1 id="cb-cat-title">
            <span><?php _e("Monthly Archives", "cubell"); ?> <i class="fa fa-long-arrow-right"></i></span> <?php the_time(get_option('date_format')); ?>
        </h1>

    <?php } elseif (is_year()) { ?>
        <h1 id="cb-cat-title">
            <span><?php _e("Yearly Archives", "cubell"); ?> <i class="fa fa-long-arrow-right"></i></span> <?php the_time(get_option('date_format')); ?>
        </h1>
    <?php } ?>

代码语言:javascript
复制
<div id="main" class="clearfix" role="main">

    <?php if (have_posts()) {

                        get_template_part('cat', 'style-a');
         } ?>

</div> <!-- end #main -->

<?php get_sidebar(); ?>

我该把代码放在哪里呢?

谢谢@sirBlond Hi这里是cat-style-a.php的代码

再次感谢:)快到了

代码语言:javascript
复制
<?php /* Category/Blog Style A */

if ( is_home() || is_category() ) {

  $cb_current_cat = get_query_var('cat');
  $cb_cpt_output = cb_get_custom_post_types();
  $cb_paged = get_query_var('paged');
  $cb_grid_size = NULL;

  if ( $cb_paged == false ) {
    $cb_paged = 1;
  }

  if ( is_category() == true ) {
    $cb_grid_size = cb_get_category_offset();
  } elseif ( is_home() == true ) {
    $cb_grid_size = cb_get_bloghome_offset();
  }

  if ( $cb_grid_size != NULL ) {
    $cb_offset_loop = 'on';
  } else {
    $cb_offset_loop = NULL;
  }

  $cb_featured_qry = array( 'post_type' => $cb_cpt_output, 'cat' => $cb_current_cat, 'offset' => $cb_grid_size, 'orderby' => 'date', 'order' => 'DESC',  'post_status' => 'publish', 'cb_offset_loop' => $cb_offset_loop, 'paged' => $cb_paged );
  $cb_qry = new WP_Query( $cb_featured_qry );

} else {

  global $wp_query;
  $cb_qry = $wp_query;

}

if ( ! isset( $cb_category_color_style ) ) {
    $cb_category_color_style = NULL;
  }

if ( $cb_qry->have_posts() ) : while ( $cb_qry->have_posts() ) : $cb_qry->the_post();

  $cb_meta_onoff = ot_get_option( 'cb_meta_onoff', 'on' );
  $cb_cat_id = get_the_category( $post->ID );
  $cb_post_id = $post->ID;
  $cb_post_format_icon = cb_post_format_check( $cb_post_id );
  $cb_global_color = ot_get_option( 'cb_base_color', '#eb9812' );

  $cb_category_color = cb_get_cat_color( $cb_post_id );
?>

<article id="post-<?php the_ID(); ?>" class="cb-blog-style-a clearfix<?php if (is_sticky()) echo ' sticky'; if ( $cb_category_color_style != NULL ) { echo ' ' . $cb_category_color_style; } ?>" role="article">

  <div class="cb-mask" style="background-color:<?php echo $cb_category_color; ?>;">

    <?php
        cb_thumbnail('300', '200');
        echo cb_review_ext_box( $cb_post_id, $cb_category_color );
        echo $cb_post_format_icon;
    ?>

  </div>

  <div class="cb-meta">

      <h2 class="h4"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <?php echo cb_byline(); ?>
      <div class="cb-excerpt"><?php echo cb_clean_excerpt( 210, false ); ?></div>

  </div>

</article>

<?php

  endwhile;
  cb_page_navi();
  endif;
  wp_reset_postdata();

?>
EN

回答 1

Stack Overflow用户

发布于 2014-07-30 19:02:02

我用sharethis插件(link to WP repo)做了类似的事情。它提供了一个现成的模板标签,可以在您想要的任何地方使用。

下面是我在小部件中实现的addthis按钮:

代码语言:javascript
复制
<ul class="addthis_toolbox addthis_default_style footer-social-list">
  <li><a class="addthis_button_tweet"></a></li>
  <li><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a></li>
  <li><a class="addthis_button_google_plusone" g:plusone:annotation="bubble" g:plusone:size="medium"></a> </li>
  <li><a class="icon icon_rss" href="<?php bloginfo('url');?>/feed/"></a></li>
</ul>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js"></script>

..。下面是模板实现的一部分:

代码语言:javascript
复制
<div class="blog-post-soc">
    <?php
        $json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode(get_permalink()));
        $counts = json_decode($json, true);
    ?>
    <ul class="social-count-button-lists">
        <li>
            <span class="icon icon25 icon_gplus"></span>
            <span class="count"><?php echo  $counts["GooglePlusOne"] ?></span>
        </li>
        <li>
            <span class="icon icon25 icon_twitter"></span>
            <span class="count"><?php echo  $counts["Twitter"] ?></span>
        </li>
        <li>
            <span class="icon icon25 icon_fb"></span>
            <span class="count"><?php echo  $counts["Facebook"]["like_count"] ?></span>
        </li>
        <li>
            <span class="icon icon25 icon_in"></span>
            <span class="count"><?php echo  $counts["LinkedIn"] ?></span>
        </li>
        <li>
            <span class="icon icon25 icon_pin"></span>
            <span class="count"><?php echo  $counts["Pinterest"] ?></span>
        </li>
        <li>
            <a href="<?php get_bloginfo('url') ?>/feed/" class="icon icon25 icon_rss"></a>
        </li>
    </ul>
</div>

这是一种旧的实现(WP3.1),但我不认为到目前为止有什么改变。

还有另一种选择。您可以使用您的代码,但您需要在循环结束前将其粘贴到archive.php或index.php (或两者)中-它将如下所示:

while(have_posts()): #some code here the_excerpt(); //or the_content(); if (function_exists('ADDTOANY_SHARE_SAVE_KIT')): ADDTOANY_SHARE_SAVE_KIT(); endif; endwhile;

此外,最好遵循最佳实践,在子主题中进行所有更改,而不是您购买的主题。这个小把戏将来会帮你节省很多时间。

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

https://stackoverflow.com/questions/25034980

复制
相关文章

相似问题

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