2015-10-05 121 views
0

这是我第一次为WordPress构建一个插件。我了解了基础知识,但现在我正试图在右下角显示div,更像是仅在首页右下角的小弹出窗口。我上传的PHP代码不起作用,它不断让我的网站崩溃。PHP WordPress插件 - 如何仅在静态主页上显示div?

我的错误在哪里?

请解释你的答案。谢谢!

代码:

<?php 
/* 
Plugin Name: My First Plugin 
Plugin URL: http://www.martinshabacom.ipage.com/test 
Description: An awesome facebook popup plugin that will amaze you! 
Author: Martin 
Version: 1.0 
Author URL: http://www.martinshabacom.ipage.com/test 
*/ 
add_action('admin_menu', 'myfirstplugin_admin_actions'); 
function myfirstplugin_admin_actions() { 
    add_options_page('MyFirstPlugin', 'MyFirstPlugin', 'manage_options', __FILE__, 'myfirstplugin_admin'); 
} 

function myfirstplugin_admin() 
{ 
?> 
<style> 
    .wrap { 
     width:100%; 
     height:auto; 
     } 

    .popup { 
     position:fixed; 
     bottom:0; 
     right:0; 
     width:325px; 
     height:200px; 
     background-color:#09f; 
    } 
</style> 


    <div class="wrap"> 

    <h1>Hello World!</h1><br> 
    <h4>Hope you like my awesome popup!</h4> 

    </div> 



<?php if(is_front_page()) { 
     <div class="popup">Testing Div Tag On The Bottom Right Corner...</div> 
    } 
?> 
<?php 
} 
?> 
+1

当你说,“[[]]不断崩溃我的网站”,你是什么意思?你有没有检查Apache错误日志输出可能涉及? – Nathan

+0

当我删除插件文件时,我的网站又回来了! 我的意思是它显示500错误的东西。 –

+0

我建议查看Apache错误日志以找出原因。此外,重要的是要注意确切的错误代码(不是“500错误的东西”)。 – Nathan

回答

1

以下部分不应该inluded的PHP if条款..

<div class="popup">Testing Div Tag On The Bottom Right Corner...</div> 

一般来说,我认为这是更好地使用替代语法,使你的代码更易读:

<?php if (...) : ?> 
     your html code 
<?php endif; ?> 

编号:http://php.net/manual/en/control-structures.alternative-syntax.php

+0

我会如何将首页回复到首页?我会在“你的html代码”里面放什么 –