您好,我创建了这个脚本,以在每一天和当前关系中看到一位圣人。
我用在模板的标题上,效果很好:
<?php
//Date parameter
$currentDay = date(\'j\');
$currentMonth = date(\'n\');
//wp query to show saints name
$con = mysqli_connect("localhost","mydb","mypassword","myuser");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "select * from santi where numero_giorno= ".$currentDay." and numero_mese= ".$currentMonth;
$result = mysqli_query($con, $sql);
if (mysqli_affected_rows($con)>0) {
while($row = $result->fetch_assoc()){
?>
<span id="txtSaintName"><?php echo $row[\'nome\']?></span>
<?php
}
mysqli_close($con);
}
?>
现在,我需要将其转换为短代码,以便在小部件中使用。
我尝试这样做,但如果我复制页面或小部件上的短代码,并试图看到我只使用当天的数字,而不是文本。哪里错了?
<?php
add_shortcode("separatore", "separatore_html_render");
function separatore_html_render( $atts ) {
return <?php
//Date parameter
$currentDay = date(\'j\');
$currentMonth = date(\'n\');
//wp query to show saints name
$con = mysqli_connect("localhost","mydb","mypassword","myuser");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "select * from santi where numero_giorno= ".$currentDay." and numero_mese= ".$currentMonth;
$result = mysqli_query($con, $sql);
if (mysqli_affected_rows($con)>0) {
while($row = $result->fetch_assoc()){
?>
<span id="txtSaintName"><?php echo $row[\'nome\']?></span>
<?php
}
mysqli_close($con);
}
?>;
}