Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从WordPress function.php调用函数到page-home.php_Javascript_Php_Html_Css_Wordpress - Fatal编程技术网

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

Javascript 从WordPress function.php调用函数到page-home.php,javascript,php,html,css,wordpress,Javascript,Php,Html,Css,Wordpress,我被这件事难住了。请帮忙。基本上,我试图在图片上创建一个悬停图标,以显示社交图标的效果。单击社交图标将在新窗口中打开社交网站的相关页面。我得到了悬停工作,除了onclick根本没有打开 我的主要社交图标函数位于functions.php中,如下所示: function tfd_social_buttons($content) { global $post; $permalink = get_permalink($post->ID); $title = get_the_title()

我被这件事难住了。请帮忙。基本上,我试图在图片上创建一个悬停图标,以显示社交图标的效果。单击社交图标将在新窗口中打开社交网站的相关页面。我得到了悬停工作,除了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');'
功能tfd\u社交按钮($content){
全球$员额;
$permalink=get\u permalink($post->ID);
$title=获取标题();
如果(!is_feed()&&!is_home()&&!is_page()){
$content=$content'
分享
';
}
返回$content;
}
添加过滤器(“内容”、“tfd社交按钮”);“
这就是我试图在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上调用该函数。任何帮助都将不胜感激。出于安全原因,Wordpress通常会停止一些代码行,问题是它不会通知您。
试着用这个在post中插入代码,当你安装插件时,把代码放在[script]和[/script]之间。

你最好在问这个问题;e、 g.将“facebook-share”更改为“facebook共享”。此外:您是否在浏览器控制台中看到任何javascript错误?