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.
Related
I'm using FacetWP to build a filter form. Unfortunately, my masonry layout is braking when I select any option in the form. Results are presenting as a single column, instead of 3. Weird is that F5 makes the order (3 columns) right.
I was trying to use these methods: https://facetwp.com/documentation/template-configuration/ and this one: https://facetwp.com/using-facetwp-with-existing-template-files/
My code is
<div id="primary" class="content-area col-md-9 <?php echo sydney_blog_layout(); ?>">
<main id="main" class="post-wrap" role="main">
<?php
$args = array(
'post_type' => 'nieruchomosci',
'posts_per_page' => 12,
);
$query = new WP_Query( $args );?>
<?php if ( $query->have_posts() ) : ?>
<header class="page-header">
<h3 class="archive-title">Szukaj nieruchomości</h3>
</header><!-- .page-header -->
<div class="wyszukiwarka"><?php echo facetwp_display( 'facet', 'rodzaj' ); ?><?php echo facetwp_display( 'facet', 'typ' ); ?><?php echo facetwp_display( 'facet', 'lokalizacja' ); ?></div>
<div class="posts-layout facetwp-template">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() && ( get_theme_mod( 'index_feat_image' ) != 1 ) ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail('sydney-large-thumb'); ?>
</div>
<?php endif; ?>
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="title-post entry-title">', esc_url( get_permalink() ) ), '</h2>' ); ?>
</header><!-- .entry-header -->
<div class="entry-post">
<?php the_field('cena'); ?> PLN | <?php the_field('powierzchnia'); ?> m<sup>2</sup></br>
<?php echo get_the_term_list( $post->ID, 'rodzaj', '', ', ', '' ) ?> na <?php echo get_the_term_list( $post->ID, 'typ', '', ', ', '' ) ?> w miejscowości <?php echo get_the_term_list( $post->ID, 'lokalizacja', '', ', ', '' ) ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'sydney' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-post -->
<footer class="entry-footer">
<?php sydney_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
<?php endwhile; ?>
</div>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
Any advice will be very nice.
Actually I got his to work (using Masonry PACKAGED v4.1.1 & imagesLoaded PACKAGED v3.1.8):
$(document).on('facetwp-loaded', function() {
var $grid = $( '.grid' ).imagesLoaded( function() {
$grid.masonry("reloadItems");
$grid.masonry( {
itemSelector : '.loop-entry',
gutter : 30,
columnWidth : 240,
isAnimated : true,
animationOptions : {
duration : 300,
easing : 'easeInOutCirc',
queue : false
}
});
});
});
Try reload layout on facetwp-loaded event. From your question it is unclear how a masonry layout was created. Assuming it is masonry.js, you can do layout when FacetWP finishes loading like this:
$(document).on('facetwp-loaded', function() {
// do layout when FacetWP finishes
$grid.masonry('layout');
});
Check more here
https://facetwp.com/documentation/facetwp-loaded/
I would like to have two different search results depending on the page, that the user is on.
I have duplicated how the previous search contents would display, added the extra code that I want the staff search to show, and then put an if statement around it.
If user is on page 'staff' -
then show this
Else
show this.
I cant seem to get the if-statement to work, any help would be appreciated.
EDIT
This is the original working code, before i put the IF statement in, to try and create another set of results for staff searching from a specific page.
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
This is the coding after i've put the if-statement in -
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (is_page('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?><?php the_meta(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php } else { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php } endif; ?>
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
Edit 2 Match
<?php
if ( is_home() ) {
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : get_query_var( 'paged' );
$args = array(
'showposts' => (int) get_option('trim_homepage_posts'),
'paged' => $paged,
'category__not_in' => (array) get_option('trim_exlcats_recent'),
);
query_posts( apply_filters( 'et_home_args', $args ) );
}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($post->post_name('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?><?php the_meta(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php else : ?>
<article class="entry post clearfix preownedSearch">
<h2 class="et_pt_portfolio_title"><?php the_title(); ?></h2>
<?php
$index_postinfo = get_option('trim_postinfo1');
if ( $index_postinfo ){
echo '<p class="meta">';
et_postinfo_meta( $index_postinfo, get_option('trim_date_format'), esc_html__('0 comments','Trim'), esc_html__('1 comment','Trim'), '% ' . esc_html__('comments','Trim') );
echo '</p>';
}
?>
<div class="post-content clearfix">
<?php
$thumb = '';
$width = apply_filters('et_image_width',260);
$height = apply_filters('et_image_height',170);
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if ( '' != $thumb && 'on' == get_option('trim_thumbnails_index') ) { ?>
<div class="featured_box filter">
<a href="<?php the_permalink(); ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
</a>
</div> <!-- end .featured_box -->
<?php } ?>
</div>
</article> <!-- end .post-->
<?php endif; ?>
<?php
endwhile;
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { get_template_part('includes/navigation','entry'); }
else:
get_template_part('includes/no-results','entry');
endif;
if ( is_home() ) wp_reset_query(); ?>
Your php Syntax is wrong.
PHP Syntax Check: Parse error: syntax error, unexpected 'endif' (T_ENDIF) in your code on line 7 <?php } endif;?> PHP Syntax Check: Errors parsing your code
With removing endif;you're good to go
<?php if (is_page('staff')) { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Price / Description coding -->
</article>
<?php } else { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Description coding -->
</article>
<?php } ?>
Learn more about PHP's Alternativ syntax
See explanation of using if(condition){}and if(condition):endif; at this answer
Edit:
If you're using is_page within the Loop, it'll be allways false /see Source.
Instead you could compare a chosen value (here it's staff) to any other field of your current post/page.
<?php if ( $post->post_name=='staff' ) { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Price / Description coding -->
</article>
<?php } else { ?>
<article class="entry post clearfix">
<-- Title / Thumbnail / Description coding -->
</article>
<?php } ?>
Edit No.2:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($post->post_name('stock-managers')) { ?>
<article class="entry post clearfix preownedSearch">
</article> <!-- end .post-->
<?php else : ?>
<article class="entry post clearfix preownedSearch">
</article> <!-- end .post-->
<?php endif; ?>
<?php
endwhile;
?>
this is my content.php I am trying to list 2 diffrent tag on my home page. 5 post from each tag. Example 5 tags from tag:Football down of it 5 tags from tag:Basketball and here is my content.php Thanks in advance.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
You should loop the tags and do a query for each one, and for each post insert your existing HTML, like this:
<?php
$tags = array(
'Football',
'Basketball'
);
foreach ($tags as $tag) {
query_posts(array(
'post_type' => 'post'
'posts_per_page' => 5,
'tax_query' => array(
'taxonomy' => 'post_tag',
'field' => 'name',
'terms' => $tag
)
));
if (have_posts()) {
while(have_posts()) {
the_post();
?>
///.... insert your existing code here
<?php
}
}
wp_reset_query();
}
?>
Just don't forget to insert your existing html instead of the ///.... insert your existing code here block.
Try this
<div class="relatedposts">
<h3>Related posts</h3>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football,basketball', //Tag slug
'posts_per_page'=>4, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class="relatedthumb">
<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />
<?php the_title(); ?>
</a>
</div>
<?php }
wp_reset_query();
?>
</div>
Thank you everyone!! Finally I got it using this code:
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div class="relatedposts">
<h3 class="widget-title">Football</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football', //Tag slug
'posts_per_page'=>5, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Basketball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'basketball', //Tag slug
'posts_per_page'=>3, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Handball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'handball', //Tag slug
'posts_per_page'=>2, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
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(); ?>
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();?>