【发布时间】:2026-01-11 05:05:01
【问题描述】:
我创建了包含 HTML 元素的 Wordpress 页面,例如 <div> 和 <ul>,例如
<div id="main" class="large-12 medium-12 columns clearfix" role="main">
<h2 class="press-list-header">Articles</h2>
<ul class="press-list">
</ul>
</div>
我想在这些 HTML 元素中放置这样的短代码:
<div id="main" class="large-12 medium-12 columns clearfix" role="main">
<h2 class="press-list-header">Articles</h2>
<ul class="press-list">
[picture image="http://example.com/image1.jpg" thumbnail="http://example.com/image1-thumbnail.jpg"]
[picture image="http://example.com/image2.jpg" thumbnail="http://example.com/image2-thumbnail.jpg"]
[picture image="http://example.com/image3.jpg" thumbnail="http://example.com/image3-thumbnail.jpg"]
</ul>
</div>
当我这样做时,短代码只会在呈现的页面上显示为常规文本。如果我只是将短代码放在 HTML 元素之外,那么它们可以正常地将预期内容呈现到页面上。
我怎样才能让我的短代码呈现包含在 HTML 元素中的内容?
更新
我应该更具描述性。我想让我的客户可以轻松地在 TinyMCE 编辑器中输入页面和帖子的短代码。我不希望他们不得不处理 php 或 html 代码。他们无论如何都无法访问那些.php 模板文件,因为他们不是开发人员。我已经得到了短代码,它只适用于帖子而不适用于页面。我相信这是因为我对所有页面都使用了一个名为 custom-page.php 的模板,它看起来像:
<?php /* Template Name: Custom */ ?>
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="row clearfix">
<?php the_post(); global $post; echo $post->post_content; ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
我已经确定问题出在线路上
<?php the_post(); global $post; echo $post->post_content; ?>
由于某种原因,它只是呈现短代码文本。它不允许短代码运行和呈现预期的内容。如何重写这一行以使短代码正确执行?
【问题讨论】:
标签: php wordpress wordpress-theming shortcode