简体   繁体   English

在完全自定义文件中运行wodpress简码

[英]run a wodpress shortcode in totally custom file

so I have a Wordpress page where I want to fetch the data... so I am using javascript ajax to get data from a PHP file... which is totally custom build... I want to run a shortcode of WordPress in this custom file and send the HTML of shortcode to the WordPress page... 所以我有一个Wordpress页面,我想在其中获取数据...所以我正在使用javascript ajax从PHP文件中获取数据...这是完全自定义构建...我想在其中运行WordPress的简码自定义文件,并将简码的HTML发送到WordPress页面...

here's the javascript 这是JavaScript

    <script>
    jQuery(document).ready(function(){
        showjob();
    });
    function showjob() {    
    var intrest=document.getElementById("intrest").value; 
        jQuery.ajax({
            method: 'GET',
            url: 'jobsloader.php',
            data: {
                intrest: intrest,
                type: 'need'
            },
            success: function(data) 
            {
                document.getElementById("addcontainer").innerHTML = data;
            }
        });
    }
    </script>

here's the custom file code: 这是自定义文件代码:

 <?php
 if ($_GET)
 {
 ?>

 <div class="vc_row wpb_row vc_row-fluid">

 <?php

    $intrest=$_GET['intrest'];
    $search = "SELECT * FROM `$database`.`$job` where intrest='employee' && poj='$intrest'";
    $result = mysqli_query($con, $search);
    while ($row = mysqli_fetch_array($result))
    {
?>
=======================================================================
<div class="wpb_column vc_column_container vc_col-sm-3">
    <div class="vc_column-inner ">
        <div class="wpb_wrapper">
            <div class="centered-box sc-image-centered-box">
                 <div class="sc-image sc-wrapbox sc-wrapbox-style-11 sc-wrapbox-position-centered" style="width: 100px;height: 100px;">
                    <div class="sc-wrapbox-inner"><img onclick="loaddetail(<?php echo $row['id']; ?>)" class="sc-wrapbox-element img-responsive img-circle" src="<?php echo "../cloud/ads/".$row['addpic'].".png"; ?>" alt=""></div>
                 </div>
             </div>
             <div class="wpb_text_column wpb_content_element ">
                 <div class="wpb_wrapper">
                      <p style="text-align: center;"><?php echo $row['name']; ?></p>
                 </div>         
             </div>
             <div class="vc_btn3-container vc_btn3-center">
                 <button class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-block vc_btn3-icon-left vc_btn3-color-grey"><i class="vc_btn3-icon fa fa-handshake-o"></i> Full Details</button>
             </div>
          </div>
      </div>
 </div>
 ======================================================================

So the whole above code is just the html part of the below shortcode... also this html doesnt work properly[css problems]... so i want to make the shortcode work here and then send the worked code to the wordpress page.... how to??? 因此,以上整个代码只是以下简码的html部分...该html也无法正常工作[css问题] ...所以我想在此处使简码工作,然后将已工作的代码发送到wordpress页面。 ... 如何???

or if I can send the shortcode as a text and make it work in WordPress page... that will be ok too. 或者,如果我可以将简码作为文本发送并使其在WordPress页面中工作……也可以。 but how to??? 但是如何???

 <?php echo do_shortcode("[sc_team style="horizontal" team="abc" columns="1"]"); ?>
 <?php
    }
 ?>
 </div>
 <?php  
 }
 else
 {
    echo "Please Try Again Later.";
 }
 ?>         

sorry for bad explanation, for more details plz comment .... and dont downvote cause i didnt find any answer from other places... and i am stuck on it... 对不起,不好的解释,更多的细节,请PLZ评论....并且不要downvote,因为我没有从其他地方找到任何答案...而我被困在上面...

Make it a plugin, which is easy to do. 使其成为一个插件,这很容易做到。

Create a folder named myplugin in wp-content/plugins in the folder put a file named myplugin.php (same as the folder). wp-content/plugins文件夹中创建一个名为myplugin的文件夹,并放置一个名为myplugin.php的文件(与该文件夹相同)。 In that file put this 在那个文件里放这个

<?php
/*
 * Plugin Name:   MyPlugin
 * Version:       1.00.00
 * Plugin URI:
 * Description:   Some Description
 * Author:        Me
 * Author URI:    
 * License: Copyright (c) 2018 Me. All rights reserved.
 */

if(!function_exists('myshortcode')){
    function myshortcode($atts, $contents=''){
       $atts = shortcode_atts( [
         'post_id' => '',
       ]);
       ...
   }
}

add_shortcode( 'myshortcode', 'myshortcode');

Then go to the plugin page, and enable it. 然后转到插件页面,并启用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM