doujianchao7446 2014-08-13 16:30
浏览 19

试图在Wordpress上创建个人即将推出的页面

I'm trying to replace the main content area on individual pages to say Coming soon (on two pages, but not the rest of the website). Also only want to make it so people who aren't logged in see the coming soon page and people who are logged in see the actual page, so it can be worked on. So far I have this code, which doesn't work.

add_action( 'the_content', ‘ind_coming_soon_page’ );

function ind_coming_soon_page( $content ) {
    if ( is_user_logged_in() ) {
        return;
    } else {
        if (is_page( 10142 || 9035 )) {
            echo “Coming Soon”;
        } else {
            return $content;
        }
    }
}

I keep getting the error below when trying to enable the plugin (and I don't know it works yet either), the error relates to line 18 which is echo "Coming Soon!";:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/vhosts/vagish.com/httpdocs/wp-content/plugins/test/coming-soon.php on line 18

  • 写回答

1条回答 默认 最新

  • duanpao4522 2014-08-13 18:00
    关注

    A couple things here. The first is that I think you should be using add_filter( 'the_filter', 'ind_coming_soon_page' ); instead of add_action(). I don't think there's an action hook for the_content. Here's a link to the docs on the_content() filter

    Next, I think there are some issues with your code. You need to set the string "Coming Soon" to the $content variable. The is_page() function is close, but the parameters are wrong.

    add_filter( 'the_content', ‘ind_coming_soon_page’ );
    function ind_coming_soon_page( $content ) {
    
      if ( is_user_logged_in() ) {
        return;
      } else {
        if (is_page( array( 10142, 9035 )) {
            $content = "Coming Soon";
        }
       }
      }
      return $content;
    }
    

    I moved some stuff around a bit for you. Basically, if the user is logged in, return out of there. If they're not and they're on one of those two page ids (I switched it to an array heres the reference on the codex: http://codex.wordpress.org/Function_Reference/is_page) then set the $content variable to "Coming Soon". Then regardless if those conditions are met, we return the $content variable.

    This is untested but I'm pretty sure it will work.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器