Jump to content
colintsui

Add javascript codes to the end of post metabar

Recommended Posts

colintsui    0
colintsui

Hello I'd like to edit the theme file containing the post metabar to include some javascript, preferrably inside the loop.php (because need to use php to call permalink and post title for each post) but i couldn't find this file, would you please advice me which file to edit? I've already created a child theme for this purpose.

Thanks in advance

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

Hi Colin,

This will most likely require the use of a hook. Therefore, can you provide the code you wish to add and we can point you in the right direction.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
colintsui    0
colintsui

Hello Danny,

here is the code:


<span style="padding:0 0 0 6px;"><script type="text/javascript" charset="utf-8">

(function(){

  var _w = 72 , _h = 16;

  var param = {

    url:'<?php the_permalink(); ?>',

    type:'3',

    count:'1', /**是否显示分享数,1显示(可选)*/

    appkey:'', /**您申请的应用appkey,显示分享来源(可选)*/

    title:'<?php the_title(); ?>', /**分享的文字内容(可选,默认为所在页面的title)*/

    pic:'<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>', /**分享图片的路径(可选)*/

    ralateUid:'1795478825', /**关联用户的UID,分享微博会@该用户(可选)*/

language:'zh_cn', /**设置语言,zh_cn|zh_tw(可选)*/

    rnd:new Date().valueOf()

  }

  var temp = [];

  for( var p in param ){

    temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )

  }

  document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')

})()

</script></span>

Thanks!

Share this post


Link to post
Share on other sites
Simon    247
Simon

You'd be better to use a shortcode, add this to your childtheme functions.php:


function wieboshare() {
ob_start(); ?>
<span style="padding:0 0 0 6px;"><script type="text/javascript" charset="utf-8">
(function(){
var _w = 72 , _h = 16;
var param = {
url:'<?php the_permalink(); ?>',
type:'3',
count:'1', /**是否显示分享数,1显示(可选)*/
appkey:'', /**您申请的应用appkey,显示分享来源(可选)*/
title:'<?php the_title(); ?>', /**分享的文字内容(可选,默认为所在页面的title)*/
pic:'<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>', /**分享图片的路径(可选)*/
ralateUid:'1795478825', /**关联用户的UID,分享微博会@该用户(可选)*/
language:'zh_cn', /**设置语言,zh_cn|zh_tw(可选)*/
rnd:new Date().valueOf()
}
var temp = [];
for( var p in param ){
temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
}
document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')
})()
</script></span>
<?php $code = ob_get_clean();
return $code;
}
add_shortcode( 'wieboshare', 'wieboshare' );
[/CODE]

now you can place [wieboshare] in the metabar.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • Queue-it
      By Queue-it+
      Hi,
      How can I remove the "next post" links below each post page? 
      https://queue-it.com/cdn-blog/
      Before we had a related post section, but I can't find it among any functions, widgets etc. 

    • chamois_blanc
      By chamois_blanc+
      I am trying to clone a container on a page. It throws the following javascript error:
      function l(b, c, e, f) { var g = m.a.f.get(b, p); if (!c) { if (g) throw Error("You cannot apply bindings multiple times to the same element."); m.a.f.set(b, p, !0) } I would appreciate guidance and a fix. Thank you
    • Jeremiah
      By Jeremiah+
      Error: editing.js?ver=930684:5 Uncaught TypeError: Cannot read property 'getData' of undefined
      I have all of the plugins disabled and I still receive the error.
      Page Editor will not load on page.
       
    • oseehys
      By oseehys+
      Can someone give me a breakthrough out here?
      I have been on the media player for like 5 hours now yet it is still not displaying on my media box or the textbox,
      its a free media player on soundclound
      Great day ahead to the developers out here...
      am trying to install the Toneden media player https://www.toneden.io/player to display my songs on sound cloud, i followed everything on the doc, but obviuosly am missing something i did everything i can for 5 hours yet no breakthrough, am using the textbox as display.
      This is the html script i used, what am i missing here? see it below
        (function() { var script = document.createElement('script') script.type = 'text/javascript'; script.async = true; script.src = 'http://sd.toneden.io/production/toneden.loader.js' var entry = document.getElementsByTagName('script')[0]; entry.parentNode.insertBefore(script, entry); }()); ToneDenReady = window.ToneDenReady || []; ToneDenReady.push(function() { ToneDen.player.create({''enter code here'' dom: '#player', urls: [''https://soundcloud.com/reginaspektor'' ] }); });
    • lutz
      By lutz
      Hi everybody,
      I use Pagelines for some years now, but for the first time I have to split up posts into several pages.
      Unfortunately, <!-- nextpage --> doesn't work.
      Can please someone help me, making that work?
      I don't have the time to change the theme and need the post split up because it would be way too long, espcially on mobile displays ...
      Thanks in anticipation!!!
×