繁体   English   中英

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

[英]Wordpress Custom Theme: Plugins Won't Load or Display Only Code

这是我第一次尝试纯粹从头开始创建主题。 在此之前,我只使用 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(); ?>

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

然后,在您的 index.php 文件中,除了上面所说的之外,还有一个错误,因为您正在调用 the_title () (函数),它通过 object 帖子推断帖子或页面的标题,在这种情况下应该是在 if 条件中包含的 while 循环中提取。

然后尝试如下编辑文件。

index.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(); ?>

和页面.php

<?php


get_header(); ?>



<?php while( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
<?php endwhile; ?>

<?php get_footer(); ?>

但是,在 wordpress 法典中,您会发现所有指南都写在任何类型的 function 上,别再看了。

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

暂无
暂无

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

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