从WordPress function.php调用函数到page-home.php

时间:2015-08-30 21:06:45

标签: javascript php html css wordpress

我被困在这里。请帮忙。基本上,我正在尝试在图像上创建悬停以显示社交图标效果。单击社交图标将转到新窗口中社交网站的相关页面。我得到了悬停工作,除了onclick根本没有打开。

我的主要社交图标功能在functions.php中如下:

    function tfd_social_buttons($content) {
global $post;
$permalink = get_permalink($post->ID);
$title = get_the_title();
if(!is_feed() && !is_home() && !is_page()) {
    $content = $content . '<div class="tfd-social-buttons">
<h5>SHARE ON</h5>

    <a class="icon-twitter" href="http://twitter.com/share?text='.$title.'& url='.$permalink.'"
        onclick="window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;">
        <span>Twitter</span>
    </a>    

    <a class="icon-fb" href="https://www.facebook.com/sharer/sharer.php?u='.$permalink.'"
         onclick="window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;">
        <span>Facebook</span>
    </a>

    <a class="icon-gplus" href="https://plus.google.com/share?url='.$permalink.'"
       onclick="window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;">
        <span>Google+</span>
    </a>
</div>';
}
return $content;
 }
  add_filter('the_content', 'tfd_social_buttons');'

这就是我要在page-home.php

上实现的内容
<!-- Beginning of Featured Stories -->
            <div id="freshly-pressed">
<?php
global $post;
$args = array( 'post_type' => 'post', 'posts_per_page' => -1 );
$myposts = get_posts( $args );
 foreach( $myposts as $post ) : setup_postdata($post); ?>

            <div class="press">
   <figure class="cap-bot">
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large', array('class' => 'featured-thumb grayscale')); ?></a>
           <figcaption>
      <div class="tfd-social-buttons">
<a class="icon-twitter" href="http://twitter.com/share?text='.$title.'& url='.$permalink.'"
    onclick="window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;">
    <span>Twitter</span>
</a>    

<a class="icon-fb" href="https://www.facebook.com/sharer/sharer.php?u='.$permalink.'"
     onclick="window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;">
    <span>Facebook</span>
</a>

<a class="icon-gplus" href="https://plus.google.com/share?url='.$permalink.'"
   onclick="window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;">
    <span>Google+</span>
</a>
</div>
 </figcaption>
 </figure>
                <div class="press-info">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <p><?php the_date(); ?></p><p><?php $content = get_the_content(); echo wp_trim_words( $content , '15' ); ?></p>
            </div><!-- press-info --> 

            </div><!-- press --> 
      <?php endforeach; ?> 
            </div><!-- Freshly Pressed -->   
            <!-- End of Featured Stories -->

悬停效果和图标可见但是onclick不会打开新窗口。无论如何我可以在来自functions.php的onclick上调用该函数。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

出于安全原因,Wordpress通常会停止某些代码行,问题是它不会通知您。 尝试使用此plugin在帖子中插入代码,当您安装插件时,将代码放在[script]和[/ script]之间