PHP 边栏中的代码无法正常工作
PHP code in Sidebar Not Working Correctly
我的动态 php 边栏有一些问题,想看看是否有人发现我的代码有任何问题。现在,aside 和 other sidebar 类 比代码结束更早关闭。我在想我的代码可能还有其他我不知道的错误。
我安装了一个php小部件插件,下面的代码写在侧边栏中:
<div class="sidebar-container">
<button class="accordion" style="h5">Education</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('education') . '</span>'; ?></p>
</div>
<?php if( get_field('licensescertifications') ) : ?><button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('licensescertifications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('honors') ) : ?><button class="accordion">Honors</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('honors') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('publications') ) : ?><button class="accordion">Publications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('publications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('affiliations') ) : ?><button class="accordion">Affiliations</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('affiliations') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('languages') ) : ?><button class="accordion">Languages</button>
<div class="accordion-content">
<p><?php the_field('languages'); ?></p>
<?php endif; ?>
</div>
</div>
也许你应该在每个块中替换 "endif" 的位置?并在 "echo" 行
中将 "the_field" 替换为 "get_field"
<?php if( get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('licensescertifications') . '</span>'; ?></p>
</div>
<?php endif; ?>
或很快:
<?php if( $field_data = get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . $field_data . '</span>'; ?></p>
</div>
<?php endif; ?>
我的动态 php 边栏有一些问题,想看看是否有人发现我的代码有任何问题。现在,aside 和 other sidebar 类 比代码结束更早关闭。我在想我的代码可能还有其他我不知道的错误。
我安装了一个php小部件插件,下面的代码写在侧边栏中:
<div class="sidebar-container">
<button class="accordion" style="h5">Education</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('education') . '</span>'; ?></p>
</div>
<?php if( get_field('licensescertifications') ) : ?><button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('licensescertifications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('honors') ) : ?><button class="accordion">Honors</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('honors') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('publications') ) : ?><button class="accordion">Publications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('publications') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('affiliations') ) : ?><button class="accordion">Affiliations</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . the_field('affiliations') . '</span>'; ?></p>
<?php endif; ?>
</div>
<?php if( get_field('languages') ) : ?><button class="accordion">Languages</button>
<div class="accordion-content">
<p><?php the_field('languages'); ?></p>
<?php endif; ?>
</div>
</div>
也许你应该在每个块中替换 "endif" 的位置?并在 "echo" 行
中将 "the_field" 替换为 "get_field"<?php if( get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . get_field('licensescertifications') . '</span>'; ?></p>
</div>
<?php endif; ?>
或很快:
<?php if( $field_data = get_field('licensescertifications') ) : ?>
<button class="accordion">Licenses/Certifications</button>
<div class="accordion-content">
<p><?php echo '<span class="sidebar">' . $field_data . '</span>'; ?></p>
</div>
<?php endif; ?>