简体   繁体   English

使用IF语句为Wordpress修改PHP和HTML

[英]Modifying PHP and HTML with IF statement for Wordpress

I am trying to modify this Wordpress theme: http://www.elegantthemes.com/preview/DailyNotes/ 我正在尝试修改此Wordpress主题: http : //www.elegantthemes.com/preview/DailyNotes/

For a regular Text Post, I want it to display a thumbnail picture if one exists. 对于常规的文本发布,我希望它显示缩略图(如果存在)。 Otherwise, just display the Title and Excerpt from the post. 否则,只显示帖子中的标题和摘录。 Here is the IF and ELSE statement that I am stuck on. 这是我坚持的IF和ELSE声明。 I can't get it to work and it's one or the other (always IF or always ELSE) when I change the conditional statement. 我无法使它正常工作,而当我更改条件语句时,它是另一个(总是IF或总是ELSE)。

<?php if ($arr[$j]['posttype'] == 'text') { ?>
  <div class="inside" onclick="window.location='<?php echo $arr[$j]["permalink"];?>'">
    <?php if (file_exists($arr[$j]["thumb"])) { ?>
      <span class="photospan">    
        <img src="<?php bloginfo('template_directory'); ?>/images/shadow-overlay.png" alt="thumbnail" class="thumb_overlay" />
        <?php print_thumbnail($arr[$j]["thumb"], $arr[$j]["use_timthumb"], $arr[$j]['title'] , 149, 149, '', $post = $arr[$j]["post"]); ?>
      </span>
    <?php } else { ?>
      <div class="overflow">
        <h2><?php echo($arr[$j]['title']); ?></h2>
        <?php echo $arr[$j]['excerpt']); ?>
      </div>
    <?php } ?>
    <img class="icon" src="<?php bloginfo('template_directory'); ?>/images/icon-photo.gif" alt="article post" />
  </div>
<?php }; ?>         

I tried putting in different arguments of the print_thumbnail function into the IF statement and it doesn't work. 我尝试将print_thumbnail函数的不同参数放入IF语句中,但它不起作用。 Here are the arguments for the print_thumbnail function in case it helps: 如果有帮助,以下是print_thumbnail函数的参数:

function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='') {

Can anyone tell me which argument I should use in my IF statement? 谁能告诉我在IF语句中应该使用哪个参数? Thanks in advance and let me know if you need more information. 在此先感谢您,如果您需要更多信息,请告诉我。

You need to do <?php if ($arr[$j]["thumb"]) { ?> 您需要执行<?php if ($arr[$j]["thumb"]) { ?>

and then 接着

else if (!$arr[$j]["thumb"]) {

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

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