Different permalinks for users who are not logged in
-
I’m currently showing my blog posts on a single page (via a shortcode), and I only show the excerpts to each posts. I then want only logged in users to be able to read the entire blog post, but can’t seem to figure it out.
This is my shortcode function in functions.php:
function custom_query_shortcode($atts) { // EXAMPLE USAGE: // [loop_shortcode the_query="showposts=100&post_type=page&post_parent=453"] // Defaults extract(shortcode_atts(array( "the_query" => '' ), $atts)); // de-funkify query $the_query = preg_replace('~�*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $the_query); $the_query = preg_replace('~�*([0-9]+);~e', 'chr(\\1)', $the_query); // query is made query_posts($the_query); // Reset and setup variables $output = ''; $temp_title = ''; $temp_link = ''; $temp_ex = ''; $temp_content = ''; $temp_thumb = ''; $temp_id = ''; // the loop if (have_posts()) : while (have_posts()) : the_post(); $temp_id = $post->ID; $temp_title = get_the_title($post->ID); $temp_link = get_permalink($post->ID); $temp_content = get_the_content($post->ID); $temp_ex = get_the_excerpt(); if ( has_post_thumbnail() ) { $temp_thumb = get_the_post_thumbnail($post->ID); } else { $temp_thumb = "" ; } // output all findings - $output .= "<div class='post-$temp_id' id='post-$temp_id'> <h2 class='entry-title'> <a title='$temp_title' rel='bookmark' href='$temp_link'>$temp_title</a> </h2><!--BEGIN .entry-content--> <div class='entry-content'> <div class='theExrp'> <p> <a href='$temp_link'> $temp_thumb </a> </p> <p> $temp_ex </p> </div> </div><!--END .hentry--> </div>"; endwhile; else: $output .= "Not found."; endif; wp_reset_query(); return $output; } add_shortcode("loop_shortcode", "custom_query_shortcode");
How can I alter this code to show excerpt to public users, but only logged in users can access the single posts? Non-logged in users should get redirected to the login page.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Different permalinks for users who are not logged in’ is closed to new replies.