- This topic is empty.
-
AuthorPosts
-
January 13, 2014 at 1:22 pm #160300
asiek
ParticipantI’m using a custom post type labeled “textures” and in the page template that displays all posts within that post type. I decided last minute to add the WP-members plugin in order to deny access to viewers who aren’t registered. When viewing front end, nothing works at all. The login/registration forms aren’t displayed at all. Only the content that is suppose to be blocked. Later on I realized the plugin will only work if
<?php the_content(); ?>
is used. So I replaced this//[?php /* Loop the stuff from the videos post type */ $args = array( 'post_type' => 'textures', 'posts_per_page' => 50); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();?] <li> <figure> [?php the_post_thumbnail('thummy'); ?] <figcaption> <h3>[?php the_title(); ?]</h3> [?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '[a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a]'; }?> </figcaption> </figure> </li> [?php endwhile;?]
with this//
<ul class="grid cs-style-3"> [?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?] [?php the_content(); ?] [?php endwhile; ?] [?php endif; ?] </ul>
and tried to use this code within my functions.php file, hoping it will display the desired content within
the_content
function//function new_default_content($content) { global $post; if ($post->post_type == 'textures') { $content .='<li>'; $content .='<figure>'; $content .= the_post_thumbnail('thummy'); $content .= '<figcaption>'; $content .= '<h3>'; $content .= the_title(); $content .= '</h3>'; $content .= '<span>Cool stuff brah.</span>'; if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '[a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image[/a]'; } $content .= '</figcaption>'; $content .= '</figure>'; $content .= '</li>'; } return $content; } add_filter('the_content', 'new_default_content');
After doing that the forms are displayed but when I view the blocked page, after logging in, the content is no where to be found. The blocked page is just blank.
So my question is, how can I use the WP-members plugin with custom post types? Since CPTs require a query to display all posts…
Hope that makes sense :/
I tried my best explaining the issue.
Please help.January 13, 2014 at 1:29 pm #160302chrisburton
ParticipantCan you highlight your code and click the ‘block code’ button?
January 13, 2014 at 1:37 pm #160303asiek
Participant@chrisburton Yes I realized the code was totally messed up. So I fixed it :) Thank you :D
January 13, 2014 at 1:59 pm #160306Alen
Participantthe_post_thumbnail
andthe_title
are used to echo data, try usingget_the_post_thumbnail
andget_the_title
inside your function.January 13, 2014 at 2:35 pm #160311asiek
Participant@alen I followed your instructions, but the issue still occurs :( Thanks for your time and help though.
January 13, 2014 at 9:55 pm #160338asiek
ParticipantFOUND A SOLUTION
I remembered that you can add content inside of shortcodes.
So I created my own shortcode[textures_content]
//add_shortcode( 'textures_content', 'textures_shortcode' ); function textures_shortcode( $atts ) { ob_start(); $query = new WP_Query( array( 'post_type' => 'textures', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'date', ) ); if ( $query->have_posts() ) { ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <li> <figure> <?php the_post_thumbnail('thummy'); ?> <figcaption> <h3><?php the_title(); ?></h3> <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a>'; }?> </figcaption> </figure> </li> <?php endwhile; wp_reset_postdata(); ?> <?php $myvariable = ob_get_clean(); return $myvariable; } }
Copied and pasted the shortcode and now it works perfectly!!!!!!
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.