添加一些html和php代码底部的wordpress帖子内容

时间:2017-02-05 19:25:39

标签: php html wordpress

我想在wordpress帖子内容的底部添加一些html和php代码,我知道有了这个功能代码,我可以在帖子内容的底部添加一些内容: -

   add_filter( 'the_content', 'add_before' , 20 );
function add_before( $content ) {
  $custom_content .= '<div></div>'; 
    $content = $content . $custom_content;
  return $content;
}

以下是我想在帖子内容底部插入的代码,如何将上面的代码与此方法合并以便正常工作: -

<script src="http://mlmarketing.ir/wp-content/themes/mlmarketingv2/js/jquery.min.js"></script>
<script src="http://mlmarketing.ir/wp-content/themes/mlmarketingv2/js/jquery.hashchange.min.js" type="text/javascript"></script>
<script src="http://mlmarketing.ir/wp-content/themes/mlmarketingv2/js/jquery.tab.min.js" type="text/javascript"></script>



<script type="text/javascript">
 jQuery(document).ready(function() {
document.getElementById("copyButton2").addEventListener("click", function() {
    copyToClipboardMsg(document.getElementById("copyTarget2"), "msg");
});

function copyToClipboardMsg(elem, msgElem) {
	  var succeed = copyToClipboard(elem);
    var msg;
    if (!succeed) {
        msg = "این ویژگی در مرورگر شما پشتیبانی نمی شود. لطفا از کلیدهای ترکیبی Ctrl + C استفاده نمایید."
    } else {
        msg = "لینک کوتاه این مطلب در کلیپ بورد شما کپی شد"
    }
    if (typeof msgElem === "string") {
        msgElem = document.getElementById(msgElem);
    }
    msgElem.innerHTML = msg;
    setTimeout(function() {
        msgElem.innerHTML = "";
    }, 5000);
}

function copyToClipboard(elem) {
	  // create hidden text element, if it doesn't already exist
    var targetId = "_hiddenCopyText_";
    var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
    var origSelectionStart, origSelectionEnd;
    if (isInput) {
        // can just use the original source element for the selection and copy
        target = elem;
        origSelectionStart = elem.selectionStart;
        origSelectionEnd = elem.selectionEnd;
    } else {
        // must use a temporary form element for the selection and copy
        target = document.getElementById(targetId);
        if (!target) {
            var target = document.createElement("textarea");
            target.style.position = "absolute";
            target.style.left = "-9999px";
            target.style.top = "0";
            target.id = targetId;
            document.body.appendChild(target);
        }
        target.textContent = elem.textContent;
    }
    // select the content
    var currentFocus = document.activeElement;
    target.focus();
    target.setSelectionRange(0, target.value.length);
    
    // copy the selection
    var succeed;
    try {
    	  succeed = document.execCommand("copy");
    } catch(e) {
        succeed = false;
    }
    // restore original focus
    if (currentFocus && typeof currentFocus.focus === "function") {
        currentFocus.focus();
    }
    
    if (isInput) {
        // restore prior selection
        elem.setSelectionRange(origSelectionStart, origSelectionEnd);
    } else {
        // clear temporary content
        target.textContent = "";
    }
    return succeed;
}

  });
</script>


<script type="text/javascript">
$(document).ready( function() {
         $('#tab-container').easytabs();
});
</script>

<style type="text/css">
div#preload{
        display:none;
    }
</style>
<script type="text/javascript">

window.onload=function(){
        document.getElementById('preload').style.display = 'block';
    }
</script>
<div id="preload">
    
<?php if ( get_field('show') ) : ?>
<div id="tab-container" class='tab-container'>
<ul class='etabs'>
<?php if ( get_field('download_links') ) : ?>
<li class='tab dl-color'><a href="#tabs1-dl">لینک دانلود</a></li>
<?php endif; ?>
<?php if ( get_field('forum_link') ) : ?>
<li class='tab forum-color'><a href="#tabs1-forum">لینک در انجمن</a></li>
<?php endif; ?>
<?php if ( get_field('share') ) : ?>
<li class='tab share-color'><a href="#tabs1-share">اشتراک گذاری</a></li>
<?php endif; ?>
<?php if ( get_field('info') ) : ?>
<li class='tab info-color'><a href="#tabs1-info">توضیحات</a></li>
<?php endif; ?>
<?php if ( get_field('reference') ) : ?>
<li class='tab reference-color'><a href="#tabs1-reference">مرجع</a></li>
<?php endif; ?>
<?php if ( get_field('shortlink') ) : ?>
<li class='tab shortlink-color'><a href="#tabs1-shortlink">لینک کوتاه</a></li>
<?php endif; ?>

<li class='tab barchasb-color'><a href="#tabs1-barchasb">برچسب ها</a></li>


</ul>



<div class='panel-container'>

<?php if ( get_field('download_links') ) : ?>
<div id="tabs1-dl">
<h3>لینک (های) دانلود</h3><br/>
<?php if ( get_field('dl_info1') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info1');?>  
<a href="<?php echo get_field('dl_link1');?>" target="_blank"><?php echo get_field('dl_name1');?></a> |  <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size1');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info2') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info2');?>  
<a href="<?php echo get_field('dl_link2');?>" target="_blank"><?php echo get_field('dl_name2');?></a> |  <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size2');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info3') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info3');?>  
<a href="<?php echo get_field('dl_link3');?>" target="_blank"><?php echo get_field('dl_name3');?></a> |  <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size3');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info4') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info4');?>  
<a href="<?php echo get_field('dl_link4');?>" target="_blank"><?php echo get_field('dl_name4');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size4');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info5') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info5');?>  
<a href="<?php echo get_field('dl_link5');?>" target="_blank"><?php echo get_field('dl_name5');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size5');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info6') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info6');?>  
<a href="<?php echo get_field('dl_link6');?>" target="_blank"><?php echo get_field('dl_name6');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size6');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info7') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info7');?>  
<a href="<?php echo get_field('dl_link7');?>" target="_blank"><?php echo get_field('dl_name7');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size7');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info8') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info8');?>  
<a href="<?php echo get_field('dl_link8');?>" target="_blank"><?php echo get_field('dl_name8');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size8');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info9') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info9');?>  
<a href="<?php echo get_field('dl_link9');?>" target="_blank"><?php echo get_field('dl_name9');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size9');?><br/>
<?php endif; ?>

<?php if ( get_field('dl_info10') ) : ?>
<img src="http://mlmarketing.ir/images/dl_icon.png">
<?php echo get_field('dl_info10');?>  
<a href="<?php echo get_field('dl_link10');?>" target="_blank"><?php echo get_field('dl_name10');?></a> | <img src="http://mlmarketing.ir/images/size_icon.png"> حجم: <?php echo get_field('dl_size10');?><br/>
<?php endif; ?>

<?php echo get_field('download_links'); ?>
</div><?php endif; ?>



<?php if ( get_field('forum_link') ) : ?><div id="tabs1-forum">
<h3>لینک مطلب در انجمن</h3><br/>
به منظور بحث و گفتگو در مورد این مطلب، می توانید به تاپیک آن در تالار گفتمان مراجعه نمایید:<br/><br/><div style="align:center; border: 2px solid #FFA459; border-radius: 8px; margin-left:auto; margin-right:auto; background-color: #FFDAC7; width:auto; height:20px; text-align:center; padding: 5px; font-size:16px;">
<a href="<?php echo get_field('forum_link');?> " target="_blank"><?php the_title(); ?></a></div>
</div><?php endif; ?>


<script type="text/javascript">
// Popup window code
function newPopup(url) {popupWindow = window.open(url,'popUpWindow','height=600px,width=850px,top=70px,left=270px, resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes')}
</script>

<?php if ( get_field('share') ) : ?><div id="tabs1-share">
<h3>اشتراک گذاری این مطلب در شبکه های اجتماعی</h3><br/>
با به اشتراک گذاشتن این مطلب، فرصت دیدن مطالب مورد علاقه ی خود را به دوستانتان هدیه دهید...!<br/>
هم اکنون می توانید این مطلب را توسط شبکه های اجتماعی زیر به اشتراک بگذارید<br/><br/>
<div class="social">

<div class="socialicons"><a class="telegram" href="JavaScript:newPopup('https://telegram.me/share/url?url=<?php the_permalink(); ?>')" title="ارسال به تلگرام">تلگرام</a></div>

<div class="socialicons"><a class="twitter" href="JavaScript:newPopup('https://twitter.com/home?status=Reading: <?php the_permalink(); ?>')" title="این مطلب را توئیت کن !">Twitter</a></div>

<div class="socialicons"><a  class="facebook" href="JavaScript:newPopup('https://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>')" title="این مطلب را در فیسبوک شیر کنید !">Facebook</a></div>

<div class="socialicons"><a  class="google-plus" href="JavaScript:newPopup('https://plus.google.com/share?url=<?php the_permalink(); ?>')" title="این مطلب را در گوگل پلاس منتشر کنید !">Google+</a></div>

<div class="socialicons"><a  class="cloob" href="JavaScript:newPopup('http://www.cloob.com/share/link/add?url=<?php the_permalink(); ?>&title=<?php echo get_the_title(); ?>')" title="این مطلب را در کلوب منتشر کنید !">کلوب</a></div>

<div class="socialicons"><a  class="facenama" href="JavaScript:newPopup('http://facenama.com/links/?url=<?php the_permalink(); ?>&title=<?php echo get_the_title(); ?>')" title="این مطلب را در فیس نما منتشر کنید !">فیس نما</a></div>


<div class="socialicons"><a  class="reddit" href="JavaScript:newPopup('http://www.reddit.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>')" title="این مطلب را در Reddit منتشر کن !">Reddit</a></div>

<div class="socialicons"><a  class="stumbleupon" href="JavaScript:newPopup('http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>')" title="این مطلب را در Stumble it منتشر کن !">Stumble it</a></div>

<div class="socialicons"><a  class="digg" href="JavaScript:newPopup('http://digg/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>')" title="این مطلب را در Digg this! منتشر کنید !">Digg This !</a></div>

<div class="socialicons"><a  class="linkedin" href="JavaScript:newPopup('http://www.linkedin.com/shareArticle?mini=true&amp;title=<?php the_title(); ?>&amp;url=<?php the_permalink(); ?>')" title="این مطلب را در لینکدین منتشر کنید !">Share on LinkedIn</a></div>

<div class="socialicons"><a  class="pinterest" href="JavaScript:newPopup('http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $url; ?>')" title="این مطلب را در Pinterest منتشر کنید !">Pinterest</a></div>

<div class="socialicons"><a  class="delicious" href="JavaScript:newPopup('http://del.icio.us/post?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>')" title="این مطلب را در Del.icio.us منتشر کنید !">Del.icio.us</a></div>


</div>
<div align="center">با اشتراک گذاری این مطلب، دوستان خود را از آن آگاه سازید</div>
</div><?php endif; ?>

<?php if ( get_field('reference') ) : ?><div id="tabs1-reference">
<h3>معرفی مرجع(های) این مطلب</h3><br/>
<?php echo get_field('reference'); ?>
</div><?php endif; ?>



<?php if ( get_field('info') ) : ?><div id="tabs1-info">
<h3>توضیحاتی پیرامون این مطلب</h3><br/>
<?php echo get_field('info'); ?>
</div><?php endif; ?>

<?php if ( get_field('shortlink') ) : ?><div id="tabs1-shortlink">
<h3>لینک کوتاه به این مطلب</h3><br/><div id="copyTarget2" style="font-family:'time new roman'; align:center; border: 2px solid #9E66E8; border-radius: 15px; margin-left:auto; margin-right:auto; background-color: #D9BDFF; width:450px; height:26px; text-align:center; padding: 5px; font-size:20px;">
<?php echo get_field('shortlink'); ?></div><button id="copyButton2" class="action-button-copy shadow-copy animate-copy green-copy">کپی</button><div id="msg" class="copymsg"></div>
</div>
<?php endif; ?>

<div id="tabs1-barchasb">
<h3>فهرست برچسب ها برای این مطلب:</h3><br/>
        <?php if(get_the_tags()) {
                ?><div style="float:right;"><img src="http://mlmarketing.ir/wp-content/themes/bazar2/images/tags.png"></div>
                <?php the_tags( '<div class="entry-tag-links"><span>' . __( '' ) . '</span>', '', '</div>' ); ?><?php
            }
        ?> 
</div>

</div> </div>
<?php endif; ?>    
    </div> 

1 个答案:

答案 0 :(得分:0)

如果您具有PHP代码,并且想要在HTML文档中运行它,则只需使用<?php来指示PHP的开始,并使用?>来指示其结束。例如,使用您的代码...

<?php

    add_filter( 'the_content', 'add_before' , 20 );
    function add_before( $content ) {
    $custom_content .= '<div></div>'; 
    $content = $content . $custom_content;
    print($content);

?>

<div class='panel-container'>

我将传统上与函数声明关联的return()语句更改为简单的print()语句,以显示$content变量。

确保将此PHP放置在HTML中您希望显示PHP结果的位置。您的帖子中没有指出这一点,但是我相信您会有所想法。