Guest User

Untitled

a guest
Jan 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. if ( have_posts() ) :
  2. while ( have_posts() ) : the_post();
  3. // the loop
  4. $private = get_post_custom_values('private'); // read custom field
  5.  
  6. if (isset($private[0]) && $private[0] == 'yes' ) { // if the post is private
  7.  
  8. if ( is_user_logged_in() ) {// and if the user is logged in
  9. // display private post ?>
  10. <div>
  11. <h4><?php the_title(); ?></h4>
  12. <?php get_post_custom_keys();?>
  13. <p><?php the_content(); ?></p>
  14. <p><a href="<?php echo get_post_meta($post->ID, "resourcelink", true); ?>">Resource Link</a></p>
  15. <?php if (get_post_meta($post->ID, "private", true)==yes) {?>
  16. <p class="private">This document private.</p>
  17. <?php } ?>
  18. </div>
  19. <?php }
  20.  
  21. else { // if the user is not logged in
  22. // want make the a login link, with redirect back to this page
  23. // but now just tells user to log in ?>
  24. <div>
  25. echo the_title('<h4>','</h4>');
  26. get_post_custom_keys();?>
  27. <p><?php the_content(); ?></p>
  28. <?php echo '<p>Private resource &mdash; please log in to read.</p>';
  29. }
  30. }
  31. else { // if the post is public
  32. // display public post, for every visitor ?>
  33. <div>
  34. <h4><?php the_title(); ?></h4>
  35. <?php get_post_custom_keys();?>
  36. <p><?php the_content(); ?></p>
  37. <p><a href="<?php echo get_post_meta($post->ID, "resourcelink", true); ?>">Resource Link</a></p>
  38. </div>
  39. <?php }
  40. endwhile;
  41. endif;
  42. ?>
Add Comment
Please, Sign In to add comment