2014-07-18 113 views
-2

好吧,我们假设我有一个名为“/ deals /”的帖子。我想知道是否可以允许访问者看到那个slu and和简短的帖子描述,但是除非他们已经登录,否则实际上并没有自己访问完整的帖子?有没有可以实现这一目标的插件?或者一些代码?谢谢!是否可以限制访问特定slug下的帖子?

编辑:这个问题并不像你们许多人认为的那样简单和干燥。我不在寻找页面限制器。我想要一些能自动限制哨子下的帖子的东西,但不是slu itself本身......

+0

我试过了。任何想法我应该搜索什么关键字?我有没有运气 – Harry

+1

@哈里:可能_“wordpress插件限制访问”_将做的伎俩。我建议你关闭/删除你的问题,如果只是因为你可能会投票几次 –

+0

@EliasVanOotegem的权利,我已经尝试过了。但是我正在寻找的东西是自动限制slug下的任何东西。这些插件只允许你手动限制东西 – Harry

回答

1

这应该为你做。魔术来自WordPress功能is_user_logged_in。将其另存为taxonomy.php(如果需要,也可以使用其他更具体的模板之一,但可能需要进行一些调整)。

<?php 
//Get the WordPress header 
get_header(); 

//Get our current term 
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); 
if(false === $term) 
{ 
    echo 'No term found'; 
} 
else 
{ 
    //Output the header 
    echo esc_html($term->name); 
    echo '<br />'; 
    echo esc_html($term->description); 

    //The Loop 
    if (have_posts()) 
    { 
     while (have_posts()) 
     { 
      the_post(); 

      if(true === is_user_logged_in()) 
      { 
       //Logged in users see this 
       the_title(); 
       echo '<br />'; 
       the_content(); 
       echo '<br />'; 
      } 
      else 
      { 
       //Everyone else sees this 
       the_title(); 
       echo '<br />'; 
      } 
     } 
    } 

} 
get_footer(); 
+0

真棒,谢谢克里斯!像魅力一样工作。真的很感激它。 – Harry

相关问题