I'm trying to paginate a current category. But when I go to the next page, wordpress not show only all post of the current category, wordpress show all post of all categories. Somebody can help me?
Category.php
<!-- loop -->
<?php $cat_ID = get_query_var('cat'); ?>
<?php query_posts('&cat=<' . $cat_ID . '&showposts=6'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-sm-12 col-md-6 col-xs-12 col-lg-4">
<div class="thumbnail">
<article>
<?php the_post_thumbnail('photo-thumbnail') ?>
<div class="caption">
<h3><?php the_title(); ?></h3>
<!-- añade custom field autor del relato -->
</div>
</article>
</div>
<div class="thumbnailFooter">
<div class="pull-left" style="margin-bottom: 4px;">
<?php echo get_avatar(get_the_author_meta('ID'), 32); ?>
</div>
<div class="smallFont pull-left" style="margin-left: 5px; width: 270px;">
<span class="blue bold"><?php the_author(); ?></span>
</div>
<div class="verySmallFont pull-left" style="margin-left: 5px; margin-top: -3px;">
en <?php the_category(none); ?> el <?php the_date(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php my_pagination(); ?>
<?php else : ?>
<?php endif; ?>
<!-- / fin del loop -->
Function.php
<?php
if (!function_exists('my_pagination')) :
function my_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links(
array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'prev_text' => __('« Anterior'),
'next_text' => __('Siguiente »'),
)
);
}
endif;
EDIT::::::::::
After do suggested changes (but don't works). Wordpress not limit 5 post per page and the paginator not appear.
<!-- loop de post -->
<?php
$project_category = wp_get_post_categories($post->ID); ?>
<?php $query = new WP_Query(array('posts_per_page' => 5)); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-sm-12 col-md-6 col-xs-12 col-lg-4">
<div class="thumbnail">
<article>
<?php the_post_thumbnail('photo-thumbnail') ?>
<div class="caption">
<a href="<?php the_permalink(); ?>">
<h3 style="font-weight:bold; margin-top: 0px; line-height: 1.3;"><?php the_title(); ?></h3>
</a>
<!-- añade custom field autor del relato -->
</div>
</article>
</div>
<div class="thumbnailFooter">
<div class="pull-left" style="margin-bottom: 4px;">
<?php echo get_avatar(get_the_author_meta('ID'), 32); ?>
</div>
<div class="smallFont pull-left" style="margin-left: 5px; width: 270px;">
<span class="blue bold"><?php the_author(); ?></span>
</div>
<div class="verySmallFont pull-left" style="margin-left: 5px; margin-top: -3px;">
en <span class="bold gray"><?php the_category(none); ?></span>
el <?php the_date(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<div style="text-align: right; padding-right: 12px;">
<?php my_pagination(); ?>
</div>
<?php else : ?>
<?php endif; ?>
<!-- / fin del loop -->
You seem to have a left angle bracket < inside your query_posts function. Try removing that.
Related
So, i was wondering if there's a way to target a specific value in a <?php the_field('title'); ?> loop.
I'm iterating over a result set of people on a site. If title equals CEO it should display in another row.
<?php
/*
Template Name: Personal
*/
?>
<?php get_header(); ?>
<div id="main" class="fullpage" style="background-image: url(<?php echo get_template_directory_uri(); ?>/img/fullpagebg.png);">
<section class="banner innerBanner">
<div class="container">
<div class="bannerContent">
<h1>Vår <strong>personal</strong></h1>
</div>
</div>
</section>
<section class="padtop0">
<div class="container-fluid">
<div class="productsMain">
<div class="row justify-content-center">
<?php
$loop = new WP_Query( array( 'post_type' => 'Persons') );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-xl-3 col-lg-4 col-md-6 wow fadeInUp" data-wow-delay=".2s">
<div class="personalbox" style="background-color: #f3f3f3; background-image: url(<?php echo get_field('bild'); ?>); background-size: <?php echo $background_size; ?>;">
<div class="personalbox-description">
<h4 style="color:#000000 !important;"><strong><?php the_field('Namn'); ?></strong></h4>
<h6 style="color:#000000 !important;;"><?php the_field('title'); ?></h6>
<br>
<h6 style="color:#000000 !important;"><strong>Telefon:</strong> <?php the_field('telefon'); ?></h6>
<h6 style="color:#000000 !important;"><strong>Mailt:</strong> <?php the_field('e-post'); ?></h6>
</div>
</div>
</a>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
I have a problem with a custom wordpress template.
I've made a categories page. Works fine on the firs view.
But when I make click on 2nd page for older posts, the browser shows me a 404 error.
I think my query needs something more, but I don't know what is or if this is the problem.
Can somebody help, please?
This is my code:
<?php
/**
* The template for displaying Category pages
*/
?>
<?php get_header(); ?>
<?php get_template_part( 'partials/linea-content', 'page' ); ?>
<div class="index categories">
<div class="col-xs-12 pre-content">
<div class="container">
<?php //Para añadir contenido se interesa ?>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-xs-12 categories-title">
<h2>Categoria: <span><?php echo get_category(get_query_var('cat'))->name; ?></span></h2>
</div>
<div id="posts" class="col-xs-12 col-sm-9">
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// Cambiamos los argumentos para buscar desde la última
$args = array(
'posts_per_page' => 2,
'orderby' => 'date',
'order' => ASC,
'category__in' => get_category(get_query_var('cat'))->cat_ID,
'paged' => $paged
);
// '&orderby=date&order=ASC&category=' . get_category(get_query_var('cat'))->cat_ID;
// volvemos a crear la consulta principal
$aux = query_posts( $args );
$cont_items = 1;
?>
<?php if ( have_posts() ) : ?>
<div class="row items-row">
<div class="col-xs-12">
<?php while ( have_posts() ) : the_post(); ?>
<!-- post -->
<div id="post-id-<?php echo $post->ID; ?>" class="item col-xs-12 col-sm-6">
<div class="row">
<div class="col-xs-12 text-center item-content">
<span class="meta-category">
<span class="meta-category-inner">
<?php
$cat = get_the_category($post->ID);
?>
<?php echo $cat[0]->name; ?>
</span>
</span>
<?php
global $wpdb;
$ppbv_tablename = $wpdb->prefix . 'popular_by_views';
$currentRow = $wpdb->get_row("SELECT * FROM {$ppbv_tablename} WHERE post_id = {$post->ID}");
$curView = 0;
if(isset($currentRow))
{
$curView = $currentRow->views;
}
?>
<div class="item-title-content">
<a href="<?php the_permalink(); ?>" title="Popsicase">
<h2 class="item-title col-xs-10 col-xs-offset-1"><?php the_title(); ?></h2>
</a>
</div>
<p class="date-cat">
<small class="col-xs-12">
<i class="fa fa-link"></i> <strong><?php the_author(); ?></strong> | <span><i class="fa fa-calendar"></i> <?php echo get_the_date();?> | <i class="fa fa-eye"></i> <?php echo $curView; ?></span>
</small>
</p>
<?php
$img_url = get_template_directory_uri() . '/assets/img/podcast.jpg';
if (get_the_post_thumbnail())
{
$img_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
}
?>
<a href="<?php the_permalink(); ?>" title="Popsicase">
<div class="item-thumbnail" style="background:url(<?php echo $img_url; ?>) no-repeat center center;">
</div>
</a>
<div class="row">
<div class="col-xs-6 text-right">
<?php /*<span class="comment"> Comentarios: <?php comments_number( '0','1','%'); ?></span>*/ ?>
</div>
</div>
<div class="item-excerpt text-left">
<div class="col-xs-12">
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
</div>
<?php if ($cont_items % 2 == 0) : ?>
</div>
</div>
<div class="row items-row">
<div class="col-xs-12">
<?php
endif;
$cont_items++;
?>
<?php endwhile; ?>
</div>
</div>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<?php
the_posts_pagination( array(
'mid_size' => 4,
'prev_text' => __( 'Artículos antiguos', 'textdomain' ),
'next_text' => __( 'Artículos nuevos', 'textdomain' ),
) );
?>
<?php /*
<div class="nav-previous alignleft"><?php next_posts_link( 'Artículos antiguos' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Artículos nuevos' ); ?></div>
*/ ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<div class="hidden-xs col-sm-3 sidebar">
<div class="row">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('main-sidebar')) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="col-xs-12 pos-content">
<div class="container">
<?php //Para añadir contenido se interesa ?>
</div>
</div>
<div class="clearfix"></div>
</div>
I need help with a product category page in Wordpress. Original code was made by someone else, and I'm fairly new to php. I may need help with looking for a way to make the product sort by date published. right now, here is the code that I have.
category-books.php
<?php
/**
* Template Name: Store Template
* #package WordPress
*/
get_header(); ?>
<div id="page-title">
<!-- 960 Container Start -->
<div class="container">
<div class="sixteen columns">
<h1>
<?php single_cat_title( '', true ); ?>
</h1>
</div>
</div>
<!-- 960 Container End -->
</div>
<?php
get_template_part( 'content', 'product4' ); ?>
<div class="blogsidebar" style="float:left !important">
<?php dynamic_sidebar('sidebar-1'); ?>
</div>
<?php get_footer(); ?>
content-product4.php
<?php function bac_wp_strip_header_tags_only( $excerpt ) {
$regex = '#(<h([1-6])[^>]*>)#';
$excerpt = preg_replace($regex,'', $excerpt);
return $excerpt;
}
add_filter( 'the_content', 'bac_wp_strip_header_tags_only', 0); ?>
<div class="container">
<?php $sidebar_side = get_post_meta($post->ID, 'incr_sidebar_layout', true);
if($sidebar_side == "left-sidebar") {
get_sidebar();
} ?>
<!-- Blog Posts ================================================== -->
<div class="twelve columns" style="float:right !important;">
<div class="product-container">
<?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- Post -->
<div <?php post_class('post'); ?> id="product-post-2Col" > <a class="post_title" href="<?php the_permalink() ?>">
<div style="margin-bottom:10px;width: 130px;height: 180px !important; border: 2px solid #000 !important;padding: 3px;float: left;margin: 0 15px 15px 0;overlay:hidden;">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail( 'medium', array( 'class' => 'store-featured-image' ) );
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/product-image.png" alt="<?php the_title(); ?>" />
<?php } ?>
</div>
<div style="min-height:40px !important;width:50% !important;float:left;">
<h4>
<?php the_title(); ?>
</h4>
</a> </div>
<?php?>
<div class="product-description-2col">
<?php the_excerpt()?>
<a style="margin-bottom: 8px;" class="post_title" href="<?php the_permalink() ?>">Learn More</a><br/>
<?php ?>
<a href="<?php the_field('buy_now_1')?>">
<div id="buybtn">Buy Now</div>
</a>
<?php ?>
</div>
<?php ?>
<p> </p>
<p> </p>
</div>
<!-- Post -->
<?php endwhile; // End the loop. Whew. ?>
</div>
<div style="text-align:center;">
<?php posts_nav_link( ' · ', 'previous page', 'next page' ); ?>
</div>
</div>
<!-- eof eleven column -->
is there a way to add something to functions.php? I've added this line but still not working:
<?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
<?php while (have_posts()) : the_post(); ?>
Thanks for the help.
Instead of using functions.php for this, create a child theme and edit a copy of the file you want to change there.
https://codex.wordpress.org/Child_Themes
I have create a custom blog page template but the problem is that i am not able to insert pagination links yet i want to display pagination links next and previous on the bottom of blogs what should i do....
here is my code
<?php /*
Template Name: My Blog Page
*/
?>
<div class="col-md-9 col-sm-9">
<!-- Blog Post -->
<?php
$args = array('post_type' => 'post', 'posts_per_page' => 10, 'ignore_sticky_posts' => 1, 'category_name' => 'blog', );
$post_type_data = new WP_Query($args);
while ($post_type_data->have_posts()):
$post_type_data->the_post();
global $more;
$more = 0; ?>
<div class="row blog-row" style="padding: 20px 0;border- bottom: 1px solid #A9A9A9;">
<div style="width: 50%;float: left">
<div class="feature-image img-overlay">
<?php if (has_post_thumbnail()): ?>
<?php $default = array('class' => 'img-responsive');
the_post_thumbnail('wl_blog_img', $default); ?>
<?php endif; ?>
</div>
</div>
<div class="feature-content" style="padding-left: 15px;display: inline-block;width: 50%">
<h3 class="h3-blog-title">
<?php echo the_title(); ?>
</h3>
<span style="padding-right: 5px"><i class="icon-picture"></i></span>
<span style="padding-right: 5px"><i class="icon-time"></i><?php echo get_the_date('j'); ?> <?php echo the_time('M'); ?>, <?php echo the_time('Y'); ?></span>
<span style="padding-right: 5px"><i class="icon-user"></i><?php echo get_the_author(); ?></span><br><br>
<?php the_excerpt(); ?>
<a class="my-btn" href="<?php echo the_permalink(); ?>">Read More</a>
</div>
<div class="feature-details1">
</div>
</div>
<?php endwhile; ?>
<!-- //Blog Post// -->
</div>
Use following code for pagination
<?php /*
Template Name: My Blog Page
*/
?><div class="col-md-9 col-sm-9">
<!-- Blog Post -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 2, 'ignore_sticky_posts' => 1, 'category_name' => 'blog', 'paged' => $paged );
$post_type_data = new WP_Query($args);
set_query_var('page',$paged);
while ($post_type_data->have_posts()):
$post_type_data->the_post();
global $more;
$more = 0; ?>
<div class="row blog-row" style="padding: 20px 0;border- bottom: 1px solid #A9A9A9;">
<div style="width: 50%;float: left">
<div class="feature-image img-overlay">
<?php if (has_post_thumbnail()): ?>
<?php $default = array('class' => 'img-responsive');
the_post_thumbnail('wl_blog_img', $default); ?>
<?php endif; ?>
</div>
</div>
<div class="feature-content" style="padding-left: 15px;display: inline-block;width: 50%">
<h3 class="h3-blog-title">
<?php echo the_title(); ?>
</h3>
<span style="padding-right: 5px"><i class="icon-picture"></i></span>
<span style="padding-right: 5px"><i class="icon-time"></i><?php echo get_the_date('j'); ?> <?php echo the_time('M'); ?>, <?php echo the_time('Y'); ?></span>
<span style="padding-right: 5px"><i class="icon-user"></i><?php echo get_the_author(); ?></span><br><br>
<?php the_excerpt(); ?>
<a class="my-btn" href="<?php echo the_permalink(); ?>">Read More</a>
</div>
<div class="feature-details1">
</div>
</div>
<?php endwhile; ?>
<div class="nav-previous alignleft"><?php previous_posts_link('« Newer posts');?></div>
<div class="nav-next alignright"><?php next_posts_link( 'Older posts »', $post_type_data->max_num_pages ); ?></div>
<!-- //Blog Post// -->
</div>
I modifying a wordpress template to be left with two columns on the main page with the following structure:
But the first 4 are of a category and the last 4 of another
The index code is:
http://pastebin.com/dMC0saBN
The page is (Columns are made, but all they do is repeat the post. They haven't order or filter)
crossfitlascondes.cl
The solution I occurred was to create two loops on the page and separated by , one to right column and one to left column. And so I can handle the code for each loop independently without interfering with the other column.
The code of index is:
<?php get_header();?>
<div id="contentslide">
<?php
include(TEMPLATEPATH . '/slide.php');
?>
</div>
<?php
get_sidebar();
?>
<div id="content">
<div class="clear">
</div>
<div id="contentleft">
<div id="noticias">Noticias</div>
<?php if ( is_home() ) { query_posts($query_string . '&cat=-27'); } ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="postleft" id="post-<?php
the_ID();
?>">
<div class="title">
<h2><a href="<?php
the_permalink();
?>" rel="bookmark" title="Permanent Link to <?php
the_title();
?>"><?php
the_title();
?></a></h2>
</div>
<div class="postmeta">
<span class="author">Posted by <?php
the_author();
?> </span> <span class="clock"> <?php
the_time('M - j - Y');
?></span> <span class="comm"><?php
comments_popup_link('0 Comment', '1 Comment', '% Comments');
?></span>
</div>
<div class="entry">
<?php
if (has_post_thumbnail()) {
?>
<a href="<?php
the_permalink();
?>"><img class="postimgleft" src="<?php
bloginfo('stylesheet_directory');
?>/timthumb.php?src=<?php
get_image_url();
?>&h=150&w=200&zc=1" alt=""/></a>
<?php
} else {
}
?>
<?php
wpe_excerpt('wpe_excerptlength_index', '');
?>
<div class="clear">
</div>
</div>
</div>
<?php
endwhile;
?>
<?php
endif;
?>
<?php
wp_reset_query();
?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php next_posts_link('Next Entries »','') ?></div>
</div>
</div>
<div id="contentright">
<div id="wod">WOD Diario</div>
<?php if ( is_home() ) { query_posts($query_string . '&cat=27&'); } ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="postright" id="post-<?php
the_ID();
?>">
<div class="title">
<h2><a href="<?php
the_permalink();
?>" rel="bookmark" title="Permanent Link to <?php
the_title();
?>"><?php
the_title();
?></a></h2>
</div>
<div class="postmeta">
<span class="author">Posted by <?php
the_author();
?> </span> <span class="clock"> <?php
the_time('M - j - Y');
?></span> <span class="comm"><?php
comments_popup_link('0 Comment', '1 Comment', '% Comments');
?></span>
</div>
<div class="entry">
<?php
if (has_post_thumbnail()) {
?>
<a href="<?php
the_permalink();
?>"><img class="postimgright" src="<?php
bloginfo('stylesheet_directory');
?>/timthumb.php?src=<?php
get_image_url();
?>&h=150&w=200&zc=1" alt=""/></a>
<?php
} else {
}
?>
<?php
wpe_excerpt('wpe_excerptlength_index', '');
?>
<div class="clear">
</div>
</div>
</div>
<?php
endwhile;
?>
<div class="clear"></div>
<?php
else:
?>
<h1 class="title">Not Found</h1>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php
endif;
?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php next_posts_link('Next Entries »','') ?></div>
</div>
<?php
wp_reset_query();
?>
</div>
</div>
<?php
get_footer();
?>
and the code CSS(summarized) is
#content {
float:left;
width: 665px;
height:100%;
padding:10px 0px 0px 0px;
margin:23px 0px 0px 15px;
display:inline;
overflow:hidden;
}
#contentleft {
float:left;
width: 50%;
height:100%;
display:inline;
overflow:hidden;
}
#contentright {
float:left;
width: 44%;
margin-left: 23px;
height:100%;
display:inline;
overflow:hidden;
}
#contentslide {
float:left;
width: 665px;
height:100%;
padding:10px 0px 0px 0px;
margin:35px 0px 0px 15px;
display:inline;
overflow:hidden;
}