WordPress自定义主题:插件将不会加载或仅显示代码

时间:2019-09-20 05:52:55

标签: php plugins wordpress-theming display

这是我纯粹从头开始创建主题的第一次尝试。在此之前,我只是使用underscores_me并对style.css进行了大部分更改,而大部分PHP都留给了我,因为我是新手。

我的问题是插件无法正常工作。我没有安装任何工具。在这一点上,我一直在尝试创建事件日历的插件,但是我假设所有插件都会出现问题。在打算显示日历的区域中,有两件事我要看到。插件生成的页面什么都没有显示(主题视觉效果除外),插入到管理员创建的页面中的插件显示插件生成的代码。

我正在使用WampServer。我有wp_footer();和wp_head();在正确的地方。我的functions.php文件是根据在https://scanwp.net/blog/create-a-wordpress-starter-theme-from-scratch/上找到的示例创建的,到目前为止,我对它所做的唯一调整就是删除了字体的那一行。

我的index.php文件如下所示:

<?php get_header(); ?>

<h1><?php echo "&#9755&nbsp;"; ?><?php the_title(); ?></h1>
 if ( have_posts() ) : 
    while ( have_posts() ) : the_post(); 
        // Display post content
    endwhile; 
endif; 
?>

<?php get_footer(); ?>

我的page.php文件如下所示:

<?php get_header(); ?>

 <h1><?php echo "&#9755&nbsp;"; ?><?php the_title(); ?></h1>
 <?= get_post_field('post_content', $post->ID) ?>

<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

首先,您必须了解在显示的文件中,没有任何函数可以调用稍后将显示页面内容的对象。

然后,除了上面所说的以外,在index.php文件中还有一个错误,因为您正在调用the_title()(函数),该函数通过post对象外推帖子或页面的标题,在此应该在if条件中包含的while循环中提取大小写。

然后尝试如下编辑文件。

index.php

public function addToCartOrderPackage($data, $proId){

    // Note: $plan_days and $days_names are that 2 div's which i am hiding and showing and wanna validate only on if these are showing 

    $pro_id = mysqli_real_escape_string($this->db->link, $proId);
    $plan_name = mysqli_real_escape_string($this->db->link, $data['plan_name']);
    $plan_days = mysqli_real_escape_string($this->db->link, $data['plan_days']);
    $days_names = mysqli_real_escape_string($this->db->link, $data['days_names']);
    $calOrderPrice = mysqli_real_escape_string($this->db->link, $data['calculated_order_price']);
    $food_time = mysqli_real_escape_string($this->db->link, $data['food_time']);
    $starts_from = mysqli_real_escape_string($this->db->link, $data['starts_from']);

    $query = "SELECT * FROM products WHERE pro_id = '$pro_id' AND pro_type = 'Plan'";
    $result = $this->db->select($query);
    $value = $result->fetch_assoc();
    $pro_name = mysqli_real_escape_string($this->db->link, $value['pro_name']);
    $pro_desc = mysqli_real_escape_string($this->db->link, $value['pro_desc']);

    $withLogin = $this->withLoginAddToCart($pro_id, $pro_name, $calOrderPrice, $pro_desc, $plan_name, $plan_days, $days_names, $food_time, $starts_from);
    return $withLogin;
}

public function withLoginAddToCart($pro_id, $pro_name, $calOrderPrice, $pro_desc, $plan_name, $plan_days, $days_names, $food_time, $starts_from){
    $userid = Session::get("user_id");
    $user_id = mysqli_real_escape_string($this->db->link, $userid);
    $arraynames = explode(",", $days_names);
    $countdays = count($arraynames);

    // Note: $plan_days and $days_names are that 2 div's which i am hiding and showing and wanna validate only on if these are showing 

    if($plan_name == "" || $plan_days == "" || $days_names == "" || $calOrderPrice == "" || $food_time == ""){
        $msg = "<div class='alert alert-danger'>All fields are required. Please fill all fields.</div>";
        return $msg;
    } else {
        if($plan_days == '5' && $countdays != 5){
            $msg = "<div class='alert alert-danger'>Please select 5 days names.</div>";
            return $msg;
        } elseif($plan_days == '6' && $countdays != 6){
            $msg = "<div class='alert alert-danger'>Please select 6 days names.</div>";
            return $msg;
        } elseif($plan_days == '7' && $countdays != 7){
            $msg = "<div class='alert alert-danger'>Please select 7 days names.</div>";
            return $msg;
        } else {
            $queryO = "INSERT INTO plan_cart(user_id, pro_id, pro_name, pro_desc, pro_price, plan_name, plan_days, days_names, food_time, starts_from, pro_type) "
                    . "VALUES('$user_id', '$pro_id', '$pro_name', '$pro_desc', '$calOrderPrice', '$plan_name', '$plan_days', '$days_names', '$food_time', '$starts_from', 'Plan')";
            $resultO = $this->db->insert($queryO);
            if($resultO != false){
                header("location: plan-cart.php");
            } else {
                $msg = "<div class='alert alert-danger'>Something's went wrong, Please try again.</div>";
                return $msg;
            }
        }
    }
}

和page.php

<?php


get_header(); ?>


<?php if( have_posts() ) : ?>
    <?php while( have_posts() ) : the_post(); ?>
        <h1><?php the_title(); ?></h1>
        <?php if( is_singular() ) : ?>
            <?php the_content(); ?>
        <?php else : ?>
            <?php the_excerpt(); ?>
        <?php endif; ?>
    <?php endwhile; ?>
<?php else: ?>
    <h1>No posts to display</h1>
<?php endif; ?>

<?php get_footer(); ?>

但是,在wordpress编解码器中,您会发现所有关于任何类型的功能都编写得很好的指南,不再赘述。

来源:https://codex.wordpress.org/