短代码有问题。。我可能不知道在哪里&;如何设置条件,以便根据toturial的主题/类别显示正确的图像。。
帮助Plz:)
function postInfoBoxSc( $atts ) {
extract( shortcode_atts( array(
\'subject\' => \'Category type\',
\'difficulty\' => \'User Types\',
\'completiontime\' => \'completion Time\'
), $atts ) );
// Set image acorring to guide type
if ($subject == \'wordpress\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/wordpress.png" alt="מדריך וורדפרס" />\';
} elseif ($subject == \'web design\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/webDesign.png" alt="מדריך בניית אתרים" />\';
} elseif ($subject == \'facebook\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/facebook.png" alt="מדריך פייסבוק" />\';
} elseif ($subject == \'RSS\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/rss.png" alt="מדריך RSS" />\';
}
return \'
<br class="clear" />
<div class="postInfoBox">
\'. $subjectImg .\'
<h5>Guide information:</h5>
<ul>
<li><strong>Category:</strong> \'. $subject .\'</li>
<li><strong>User Lever:</strong> \'. $difficulty .\'</li>
<li><strong>completion Time:</strong> \'. $completiontime .\'</li>
</ul>
</div>
\';
}
add_shortcode( \'postInfoBox\', \'postInfoBoxSc\' );
The Problem出于某种原因,$subject的值不会像其他值一样更新,不会通过快捷码传递,图像也不会因此而改变
What Am I Doing Wrong ??
(仅根据请求添加)这是我在wordpress编辑器中写帖子时需要输入的短代码:
[postInfoBox subject="somthing" difficulty="hard" completiontime="2-5 minuts"]
最合适的回答,由SO网友:Andy Adams 整理而成
我无法准确地复制您的问题,但这里有一个提示:包括一些默认行为,以防用户为主题输入错误的值:
// Set image acorring to guide type
if ($subject == \'wordpress\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/wordpress.png" alt="מדריך וורדפרס" />\';
} elseif ($subject == \'web design\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/webDesign.png" alt="מדריך בניית אתרים" />\';
} elseif ($subject == \'facebook\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/facebook.png" alt="מדריך פייסבוק" />\';
} elseif ($subject == \'RSS\') {
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/rss.png" alt="מדריך RSS" />\';
} else {
// Add default case
$subject = "Default here";
$subjectImg = \'<img src="\'.get_bloginfo(\'template_url\').\'/img/postInfoBox/default.png" alt="מדריך RSS" />\';
}
这样,即使他们给你提供了不好的数据,也总会有一个图像。