i am showing posts using shortcode, and it is showing only 5-posts, i am using wp_pagenavi plugin for pagination, but pagination not showing. Following is my code, please help.
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'cat' => '2', 'paged' => $paged );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
ob_start();
?>
<div class="clearfix"></div>
<div class="issue-articles-wrap all-articles-wrap">
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$loop->the_post();
$thumb_url = '';
$full_width = 'full-width-article';
if( has_post_thumbnail() ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$thumb_url = $thumb['0'];
$full_width = '';
}
if( $post->ID > 0 ){
?>
<div class="issue-item issue-item-<?php echo $post->ID; ?>">
<?php if( $thumb_url != '' ){ ?>
<div class="thumb-article">
<img src="<?php echo $thumb_url; ?>" alt="<?php the_title(); ?>">
</div><!--thumb-article-->
<?php } ?>
<div class="summary-article <?php echo $full_width; ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div><!--summary-article-->
<div class="clearfix"></div>
</div><!--issue-item-->
<?php
} // end of if( $post->ID > 0 )
endwhile;
wp_pagenavi();
wp_reset_query();
?>
</div><!--issue-articles-wrap all-articles-wrap-->
<?php
$rep = ob_get_contents();
ob_end_clean();
} // end of if ( $loop->have_posts() )
return $rep;
I also tried custom pagination, but it fails, if i passes posts_per_page = -1, it shows all posts.
Please help me to run pagination, thank you very much in advance.
I think you are using a plugin for display the pagination, is better to create your custome pagination.
In your function.php write this code:
if ( ! function_exists( 'your_paging_nav' ) ) :
function your_paging_nav() {
global $wp_query;
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages < 2 )
return;
?>
<nav>
<h1><?php _e( 'Posts navigation', 'framwork-translation' ); ?></h1>
<div>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'framwork-translation' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'framwork-translation' ) ); ?></div>
<?php endif; ?>
</div>
</nav>
<?php
}
endif;
and in index.php
<body <?php body_class(); ?>>
<?php get_header(); ?>
<div class="primary">
<?php if ( have_posts() ) : ?>
<!-- The loop -->
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php your_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Related
I am attempting to use a repeater with a post object inside as seen here:
Picture of ACF repeater with post object
It is only showing one out of two Reps:
Rep map
Here is the code I am using to attempt to accomplish this:
<?php
$args = array(
'post_type' => 'find-your-rep',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
$i = 0;
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); $i++ ?>
<span id="div<?php echo $i ?>" class="targetDiv">
<div class="repCard">
<?php if ( have_rows( 'reps' ) ) : ?>
<?php while ( have_rows( 'reps' ) ) : the_row(); ?>
<h3><?php the_sub_field( 'location' ); ?></h3>
<?php $rep = get_sub_field( 'rep' ); ?>
<?php if ( $rep ) : ?>
<?php $post = $rep; ?>
<?php setup_postdata( $post ); ?>
<div class="fullname"><?php the_title() ?></div>
<?php if ( get_field( 'company' ) ) : ?><div class="company">
<?php the_field( 'company' ); ?></div>
<?php endif; ?>
<?php if ( get_field( 'phone' ) ) : ?>
<div class="phone"><i class="phone icon"></i>
<a href="tel:<?php the_field( 'phone' ); ?>">
<?php the_field( 'phone' ); ?></a>.
</div>.
<?php endif; ?>
<?php if ( get_field( 'email' ) ) : ?>
<div class="email">
<i class="envelope icon"></i> <a href="mailto:<?php the_field( 'email' ); ?>">
<?php the_field( 'email' ); ?></a></div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
Sorry, there's no rep assigned to this location.
<?php endif; ?>
</div>
</span>
<?php endwhile; wp_reset_postdata(); ?>
I'd appreciate any help/direction to resolve this.
I wasn't able to find anything on here, so I am bringing this question to you. The following code does mainly what I want, only the page-cycle doesn't work: When I want to navigate to older posts, the page that is seen displays the same new posts again. How do I do this properly?
So index.php has two loops:
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach; ?>
<?php
query_posts('posts_per_page=12&offset=1');
if (have_posts()) : ?>
<h3>Headline</h3>
<?php while (have_posts()) : the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', 0 ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
Here is the explanation: One visits the blog: The most recent blog post is displayed in full length in one block, the 12 older posts (excluding the first one with offset, so 2–13) are displayed in another block with content teasers and a next-previous-navigation at the bottom to display post teasers 14–25 and so on. (The problem: it's always 2–13)
// Edit: Code in response to the top answer, now the full code of the index.php. Notice, that the HTML has changed, since I have used normalized HTML, since it should usually not matter. This times it's the actual code.
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
I am trying out this code now (14.10.17), but it doesn't add functioning page navigation...:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
New:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', $the_query->max_num_pages ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You haven't set up paging, so your query always thinks its on page 1.
Also according to the WP Developer Resources , you shouldn't use query_posts- use WP_Query or pre_get_posts instead, so I'm using WP_Query below to do your 2nd query.
Note that I've assumed you are using this on a static homepage, but I've added the change required for a custom page in comments.
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
<?php
/* Set up your pagination - $paged will contain the current page, telling WP_Query which post to start with (e.g. #13 on page 2) */
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
/* NOTE: if this is NOT on a static page
get the 'paged' query var instead of 'page', i.e.:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
*/
$display_count = 12; /* variable for the number of posts per page */
$excluded_count = 1; /* the number of posts excluded from the start position */
/* Calculate the offset, i.e. the post number to start the page with
Normally this is calculated by: ($paged-1) * $display_count
so we just need to add 1 for the one we excluded */
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
/* set up your new query passing in the page so WP_Query knows what to return */
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
/* set up your new query */
$the_query = new WP_Query( $args );
<?php if ( $the_query->have_posts() ) : ?>
<h3>Headline</h3>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
The above code is untested, but the basic logic should be right.
UPDATE:
next_posts_link and
previous_posts_link use the global variable $wp_query by default, so to make is use your custom query, pass $custom_query->max_num_pages into next_posts_link, e.g.:
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
I really can't figure this out. I'm trying to have posts all posts on a page from one category, but I still get all categories. This is the code I'm using now. I thought I could manage with WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );, but it totally drives me nuts.
<?php /* Template Name: Blog */ ?>
<?php get_header(); ?>
<div id="content-wrap">
<div id="content">
<div class="post_content">
<h1 class="archive_title"><?php the_title(); ?></h1>
<?php
$query['post_type'] = 'post';
// WP 3.0 PAGED BUG FIX
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query['paged'] = $paged;
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) { $recipe_posts->the_post(); }
query_posts($query);
if (have_posts()) : ?>
<?php $more = 0; ?>
<div class="posts">
<?php while (have_posts()) : the_post();
$is_recipe = in_category('Resep'); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<?php if (option::get('index_thumb') == 'on') {
get_the_image( array( 'size' => 'loop', 'width' => option::get('thumb_width'), 'height' => option::get('thumb_height'), 'before' => '<div class="post-thumb">', 'after' => '</div>' ) );
} ?>
<div class="details">
<h2 class="title"><?php the_title(); ?></h2>
<?php if ( option::get('display_meta') == 'on' ) { ?>
<div class="meta">
<?php
if ( $is_recipe ) {
$fields = get_fields();
if ( !empty( $fields ) ) echo $fields;
} else { ?>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/person.png'; ?>" /><?php _e('Author', 'wpzoom'); ?>:</strong><?php the_author_posts_link(); ?></p>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/clock.png'; ?>" />
<?php _e('Posted', 'wpzoom'); ?>
:</strong> <?php echo get_the_date(); ?></p>
<?php } ?>
</div>
<?php } ?>
<div class="entry">
<?php the_content('<span>'.__('Read More', 'wpzoom').' ›</span>'); ?>
</div>
<p>
<?php if ( option::get('display_readmore') == 'on' && (option::get('display_content') == 'Excerpt') ) { ?>
<a href="<?php the_permalink(); ?>" class=" clean more-link">
<?php _e( ( $is_recipe ? 'Lihat Resep' : 'Read More' ), 'wpzoom' ); ?>
</a>
<?php } ?>
<?php edit_post_link( __('Edit', 'wpzoom'), ' <small>', '</small>' ); ?>
</p>
</div>
<div class="cleaner"> </div>
</div>
<!-- /.post -->
<?php endwhile; ?>
</div>
<div class="cleaner"> </div>
<?php get_template_part( 'pagination' ); ?>
<?php wp_reset_query(); ?>
<div class="cleaner"> </div>
<?php endif; ?>
</div><!-- / .post_content -->
</div><!-- / #content -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You're making it far too complex, just specificy the stuff you need inside the while loop:
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) {
$recipe_posts->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_query();
You have entered loop inside loop, try this following with cleaning your code:
$args = array('posts_per_page' => -1 , 'category_name' => 'resep');
$recipe_posts = new WP_Query($args);
if($recipe_posts->have_posts()) :
while($recipe_posts->have_posts()) :
$recipe_posts->the_post();
?>
<h1><?php the_title() ?></h1>
<div class='post-content'><?php the_content() ?></div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
I cleaned the whole template, but posts from other categories were still there. In the end I managed with these lines
global $wp_query;
$args = array_merge( $wp_query->query, array( 'category_name' => 'resep' ) );
query_posts( $args );
$recipe_posts = new WP_Query($args);
$more = 0;
if($recipe_posts->have_posts()) :
while ($recipe_posts->have_posts()) : $recipe_posts->the_post();?>
I'm creating a custom theme, then a custom type, and when I try to put a (read more) link to the post, the anchor is not working. This is my code:
<main id="main" class="site-main" role="main">
<?php $temp_query = $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'caller_get_posts'=>1,
'post_type' => 'enfant',
'paged'=>$paged
);
$wp_query = new WP_Query($args);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID));
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="top-cont">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<!-- first one --> <img src="<?php echo $src[0];?>" />
<?php
$terms = get_the_terms($post->ID, 'maladies', '', ', ','');
if ( !empty( $terms ) ){
$numTerm = 0;
echo "<h3>Maladie : </h3>";
echo "<p>";
foreach( $terms as $term ) {
$numTerm++;
if ($numTerm == 1){
echo " ".$term->name;
}
else{
echo ", ".$term->name;
}
}
echo "</p><br/>";
}
?>
<!-- second one --> <a href="<?php the_permalink() ?>" >Lire plus ...</a>
<p><?php the_excerpt(); ?></p>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'adelia' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<div class="foot"></div>
<!--<?php edit_post_link( __( 'Edit', 'adelia' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>-->
</article><!-- #post-## -->
<?php
// If comments are open or we have at least one comment, load up the comment template
/*if ( comments_open() || '0' != get_comments_number() )
comments_template();*/
?>
<?php endwhile; // end of the loop. ?>
both line commented are not working.
it is difficult to find out bug:
i have try something for you, hope it will works.
<main id="main" class="site-main" role="main">
<?php $temp_query = $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'caller_get_posts'=>1,
'post_type' => 'enfant',
'paged'=>$paged
);
$wp_query = new WP_Query($args);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post();
//$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID));
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="top-cont">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<!-- first one --> <img src="<?php echo wp_get_attachment_image_src( get_post_thumbnail_id($post->ID));?>" />
<?php
$terms = get_the_terms($post->ID, 'maladies', '', ', ','');
if ( !empty( $terms ) ){
$numTerm = 0;
echo "<h3>Maladie : </h3>";
echo "<p>";
foreach( $terms as $term ) {
$numTerm++;
if ($numTerm == 1){
echo " ".$term->name;
}
else{
echo ", ".$term->name;
}
}
echo "</p><br/>";
}
?>
<!-- second one --> <a href="<?php the_permalink() ?>" >Lire plus ...</a>
<p><?php the_excerpt(); ?></p>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'adelia' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<div class="foot"></div>
<!--<?php edit_post_link( __( 'Edit', 'adelia' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>-->
</article><!-- #post-## -->
<?php
// If comments are open or we have at least one comment, load up the comment template
/*if ( comments_open() || '0' != get_comments_number() )
comments_template();*/
?>
<?php endwhile; // end of the loop. ?>
Thanks.
I am trying to edit a blog archive page template that will hide all output unless a password is entered. Currently when "Password protected" is selected, it only hides content entered into the page and not the category output as well.
Apparently WordPress has a function reference called Post_Password_Required that should be wrapped around the category output in the template. This way if the blog template is called and is also password protected, WordPress will block all output until the password is entered.
http://codex.wordpress.org/Function_Reference/post_password_required
Now, after arbitrarily trying to figure out where to place this code in the page-blog.php and failing i'm wondering if anyone has a better idea of where to place it.
I'm using an Elegant Themes template and their support is balls on the issue. Telling me I need to find a plugin to do this and coping out to contact a 3rd party developer to fix this. Here is the code for the blog template for reference. I appreciate any help.
<?php
/*
Template Name: Investor
*/
?>
<?php if (is_front_page()) { ?>
<?php get_template_part('home'); ?>
<?php } else { ?>
<?php
$et_ptemplate_settings = array();
$et_ptemplate_settings = maybe_unserialize( get_post_meta($post->ID,'et_ptemplate_settings',true) );
$fullwidth = isset( $et_ptemplate_settings['et_fullwidthpage'] ) ? (bool) $et_ptemplate_settings['et_fullwidthpage'] : false;
$et_ptemplate_blogstyle = isset( $et_ptemplate_settings['et_ptemplate_blogstyle'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_blogstyle'] : false;
$et_ptemplate_showthumb = isset( $et_ptemplate_settings['et_ptemplate_showthumb'] ) ? (bool) $et_ptemplate_settings['et_ptemplate_showthumb'] : false;
$blog_cats = isset( $et_ptemplate_settings['et_ptemplate_blogcats'] ) ? (array) $et_ptemplate_settings['et_ptemplate_blogcats'] : array();
$et_ptemplate_blog_perpage = isset( $et_ptemplate_settings['et_ptemplate_blog_perpage'] ) ? (int) $et_ptemplate_settings['et_ptemplate_blog_perpage'] : 10;
?>
<?php get_header(); ?>
<div id="content-left">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="entry post clearfix"<?php if ($fullwidth) echo ' style="padding-right: 10px;"'; ?>>
<?php $width = 140;
$height = 140;
$classtext = 'thumbnail alignleft';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
$thumb = $thumbnail["thumb"]; ?>
<?php if($thumb <> '' && get_option('myproduct_page_thumbnails') == 'on') { ?>
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
<?php }; ?>
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<div id="et_pt_blog">
<?php $cat_query = '';
if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
else echo '<!-- blog category is not selected -->'; ?>
<?php
$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
?>
<?php query_posts("showposts=$et_ptemplate_blog_perpage&paged=" . $et_paged . $cat_query); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( post_password_required() ) ?>
<div class="et_pt_blogentry clearfix">
<h2 class="et_pt_title"><?php the_title(); ?></h2>
<p class="et_pt_blogmeta"><?php esc_html_e('Posted','MyProduct'); ?> <?php esc_html_e('on','MyProduct'); ?> <?php the_time(get_option('myproduct_date_format')) ?>
<?php $thumb = '';
$width = 184;
$height = 184;
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
$thumb = $thumbnail["thumb"]; ?>
<?php if ( $thumb <> '' && !$et_ptemplate_showthumb ) { ?>
<div class="et_pt_thumb alignleft">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</div> <!-- end .thumb -->
<?php }; ?>
<?php if (!$et_ptemplate_blogstyle) { ?>
<p><?php truncate_post(550);?></p>
<span><?php esc_html_e('read more','MyProduct'); ?></span>
<?php } else { ?>
<?php
global $more;
$more = 0;
?>
<?php the_content(); ?>
<?php } ?>
</div> <!-- end .et_pt_blogentry -->
<?php endwhile; ?>
<div class="page-nav clearfix">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php get_template_part('includes/navigation'); ?>
<?php } ?>
</div> <!-- end .entry -->
<?php else : ?>
<?php get_template_part('includes/no-results'); ?>
<?php endif; wp_reset_query(); ?>
</div> <!-- end #et_pt_blog -->
<?php edit_post_link(esc_html__('Edit this page','MyProduct')); ?>
<div class="clear"></div>
</div> <!-- end .post -->
<?php endwhile; endif; ?>
</div> <!-- end #content-left -->
<?php if (!$fullwidth) get_sidebar(); ?>
<?php get_footer(); ?>
<?php } ?>