dtwncxs3547 2015-06-03 07:37
浏览 5

修改显示/隐藏以包含php

I am working with a show/hide script that works to show/hide text, but when I try to put some php (script to display recent posts [WordPress]) it doesn't work. Actually, the text still shows/hides, but the php displays always (below the action on the page).

I suspect it might have to do with using <span>s, which act weird in general, at least with this show/hide. If I try to put it inside a <p>, for example, it breaks the function.

Here is the code. Maybe someone can show me how to put php inside, or maybe I need a new starting point? The goal is just to display various things inside a basic light show/hide.

HTML:

<span class="span3">Hide</span>
<span class="span2">Show</span>
<p class="alert" >Some text inside the show/hide</p>

What I want to put inside the show/hide:

<div class="featured-articles">
<?php
    $args=array(
      'tag' => 'feature-left',
      'showposts'=>5,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Today';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
       <?php
      endwhile;
    } //if ($my_query)
  wp_reset_query();  // Restore global post data stomped by the_post().
?>
 </div>

CSS:

body {
  display: block;
}
.span3:focus ~ .alert {
  display: none;
}
.span2:focus ~ .alert {
  display: block;
}
.alert{display:none;}

(origin code author: Vector)

  • 写回答

1条回答 默认 最新

  • duandun2218 2015-06-03 08:04
    关注

    If I understood your question, this is what you are trying to do:

    body {
      display: block;
    }
    .span3:focus ~ .alert {
      display: none;
    }
    .span2:focus ~ .alert {
      display: block;
    }
    .alert {
      display: none;
    }
    .span2,
    .span3 {
      outline: none;
    }
    <span tabindex="0" class="span3">Hide</span>
    <span tabindex="0" class="span2">Show</span>
    <p class="alert">Some text inside the show/hide</p>

    To insert php you should of course do something such as:

    <p class="alert" ><?php echo 'Some text inside the show/hide'; ?></p>
    

    And, of course, make sure that text which you are echoing has html entities properly encoded.

    Edit:

    After your additional explanation, your problem is layout structure, you can't put div inside of p. p tag can not contain block elements. Replace p with div and it should be OK:

    <div class="alert">Your featured articles html here</div>
    
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作