display just 10 items in custom template - php

Hi i have this template in wordpress, i would like to just display 10 items, because right now in general options in wordpress i have 5 items but i would like to make an exception with this template i dont know where i have to modify the code in order to show in this template 10 items:
<?php
/*
Template Name: Blog List
*/
?>
<?php get_header(); ?>
<div class="content-wrap">
<div class="content">
<?php tie_breadcrumbs() ?>
<div id="content" class="podcast_archive">
<!--<div class="podcast_full">-->
<?php if ( have_posts() ) : ?>
<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<h1><?php _e( 'El Jurado del Pueblo' , 'ss-podcasting' ); ?></h1>
</header>
<?php
$feed_url = trailingslashit( home_url() ) . '?feed=podcast';
$custom_feed_url = get_option('ss_podcasting_feed_url');
if( $custom_feed_url && strlen( $custom_feed_url ) > 0 && $custom_feed_url != '' ) {
$feed_url = $custom_feed_url;
}
$itunes_url = str_replace( array( 'http:' , 'https:' ) , 'itpc:' , $feed_url );
?>
<section>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post(); ?>
<?php
$terms = wp_get_post_terms( get_the_ID() , 'series' );
foreach( $terms as $term ) {
$series_id = $term->term_id;
$series = $term->name;
break;
}
?>
<article class="podcast_episode">
<?php if( has_post_thumbnail() ) { ?>
<?php $img = wp_get_attachment_image_src( get_post_thumbnail_id() ); ?>
<a>" title="<?php the_title(); ?>">
<?php the_post_thumbnail( 'podcast-thumbnail' , array( 'class' => 'podcast_image' , 'alt' => get_the_title() , 'title' => get_the_title() ) ); ?>
</a>
<?php } ?>
<h3>
<strong><?php the_title(); ?></strong>
<div class="podcast_meta"><?php echo $series; ?><aside></div>
</h3>
<div id="audio">
<?php global $ss_podcasting;
$enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
if( $enclosure ) {
$audio_player = $ss_podcasting->audio_player( $enclosure );
echo $audio_player;
} ?>
<?php the_content(); ?>
</div>
<div id="audioinfo">
<a>">Descargar Audio</a>
<span class="audiometa">
Tamaño: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
</span>
</div>
<?php echo do_shortcode('[divider]');?>
</article>
<?php
endwhile;
?>
</section>
<?php endif; ?>
<?php wp_pagenavi(); ?>
<div class="podcast_clear"></div>
</div>
<?php comments_template( '', true ); ?>
</div><!-- .content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
?>
i would some advise so i can do it by myself :)
thank you very much

You'll want to use the query_posts() function for that, just before your loop.
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'showposts' => '10' ) );
query_posts( $args );
http://codex.wordpress.org/Function_Reference/query_posts

You'd need to modify your template's query. I'd suggest making use of the WP_Query class. For example:
$args = array(
'posts_per_page' => 10
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
// Loop item here
}
wp_reset_postdata();
} else {
// No results found
}

if
$args = array(
'posts_per_page' => 10
);
not work than check at back-end under Setting->Reading there is a "Blog pages show at most" if there is 5 post than it display only 5 post.

Related

How to display a specific category in wordpress post by id or other

I am trying to create a related post section at the bottom of each post. I am using YARPP plugin to generate the related posts. I want customise the a template to show, a thumbnail(Done), title(Done) and a specific category(Issue).
My issue is its displaying all assigned categories, I only want to display one child category. I have a speaker category with child categories of the names of the speakers.
Let me know if you need more information. Thanks
<h3>Related Posts</h3>
<?php if ( have_posts() ) : ?>
<div>
<?php
while ( have_posts() ) : the_post(); ?>
<div>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( $dimensions['size'], array( 'data-pin-nopin' => 'true' ) ); ?></a>
<a href="<?php the_permalink(); ?>" rel="bookmark norewrite" title="<?php the_title_attribute(); ?>">
</div>
<div>
<?php the_title(); ?>
<!-- How to add specific category -->
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if ( ! empty( $categories ) ) {
foreach( $categories as $category ) {
$term_id = '328';
$output .= '|| ' . esc_html( $category->name ) . '' . $separator;
}
echo trim( $output, $separator );
}
?>
<!-- How to add specific category END -->
</div>
<?php endif; ?>
<?php endwhile; ?>
</div>
<?php else : ?>
<p>No related photos.</p>
<?php endif; ?>
<?php $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 6, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) { setup_postdata($post); ?>
<div class="post">
<div class="post-title">
<h6 class="title"><?php the_title() ?></h6>
</div>
<div class="post-img" style="background-image: url(<?php the_post_thumbnail_url(); ?>)"></div>
</div>
<?php } wp_reset_postdata(); ?>

How to use Isotope on wordpress with custom loops and custom design?

Does someone know if it's possible to make isotopte work with a custom grid layout ?
For example, I have a custom blog page design like this
In my loop, I say : if it's the first post, take 12 col width, if it's the second and third one, take 6 col width, and all others posts, take 4 col width..
And whatever filter button I click I would like to keep that design, for example the 4th post would become the first one if I click on the corresponding category filter:
But what I get is this
Isotope doesn't respect the loop condition..
Does someone know how to acheive this?
Ok finaly I managed to make it work; Here is the code. In my home page I first build filters with checkbox. Then in my loop, I count the posts to differentiate the post size with different column sizes.
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<div class="flex-container">
<div class="flex-row">
<header class="page-header">
<?php
single_post_title('<h1 class="page-title">', '</h1>' );
?>
</header><!-- .page-header -->
</div>
<div class="flex-row">
<form action="#" method="POST" id="post_filters">
<p>Clear</p>
<?php
if( $terms = get_terms( array( 'taxonomy' => 'category' ) ) ) :
foreach( $terms as $term ) :
echo '<p><input type="radio" id="' . $term->term_id . '" value="' . $term->term_id . '" name="category_filters" class="category_filter"/><label for="' . $term->term_id. '">' . $term->name . '</label></p>';
endforeach;
endif;
?>
<!-- required hidden field for admin-ajax.php -->
<input type="hidden" name="action" value="ccfilter" />
</form>
</div>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'paged' => $paged
);
$query = new WP_Query( $args ); ?>
<?php
if ( $query->have_posts() ) :
$count = (int)0;?>
<div id="cc_posts_wrap" class="flex-row">
<?php
while ( $query->have_posts() ) : $count++;
$query->the_post();
if($count == 1){
$span = 'flex-col-xs-12';
$limit = 20;
}
if($count == 2 || $count == 3){
$span = 'flex-col-sm-6';
$limit = 13;
}
if($count > 3){
$span = 'flex-col-sm-4';
$limit = 13;
}
//If its not 3 or higher, increase the count
$termsArray = get_the_terms($post->ID, "category"); //Get the terms for this particular item
$termsString =""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug;
}
?>
<div class="<?php echo $termsString .' ' . $span ;?> item">
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<div class="post-featured-thumbnail">
<?php
if ( has_post_thumbnail() ) {
if($count == 1){
the_post_thumbnail('blog_featured');
}else{
the_post_thumbnail();
}
}
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
numgrade_category_sticker();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</div>
<div class="post-content">
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php echo excerpt($limit); ?>
</div><!-- .entry-content -->
</div>
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php endwhile;?>
</div> <!-- end isotope-list -->
<?php global $wp_query; // you can remove this line if everything works for you
if ( $wp_query->max_num_pages > 1 ) :
echo '<div id="cc_loadmore">More posts</div>'; // you can use <a> as well
endif;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
Then in functions.php, here are the admin ajax call, the load more function et the filtering function. Load more function et filtering function work well, and as we can see, I just duplicate the count loop in filtering post so it display my post as in the normal loop, with different size posts.
/*FUNCTION FILTER AND AJAX LOAD MORE*/
add_action( 'wp_enqueue_scripts', 'cc_script_and_styles');
function cc_script_and_styles() {
if ( is_home() ) {
global $wp_query;
wp_register_script( 'cc_scripts', get_stylesheet_directory_uri() . '/js/script.js', array('jquery') );
wp_localize_script( 'cc_scripts', 'cc_loadmore_params', array(
'ajaxurl' => site_url() . '/wp-admin/admin-ajax.php', // WordPress AJAX
'posts' => json_encode( $wp_query->query_vars ), // everything about your loop is here
'current_page' => $wp_query->query_vars['paged'] ? $wp_query->query_vars['paged'] : 1,
'max_page' => $wp_query->max_num_pages
) );
wp_enqueue_script( 'cc_scripts' );
}
}
add_action('wp_ajax_loadmorebutton', 'cc_loadmore_ajax_handler');
add_action('wp_ajax_nopriv_loadmorebutton', 'cc_loadmore_ajax_handler');
function cc_loadmore_ajax_handler(){
$params = json_decode( stripslashes( $_POST['query'] ), true );
$params['paged'] = $_POST['page'] + 1;
$params['post_status'] = 'publish';
query_posts( $params );
if( have_posts() ) :
while( have_posts() ): the_post();
$termsArray = get_the_terms($post->ID, "category");
$termsString ="";
foreach ( $termsArray as $term ) {
$termsString .= $term->slug;
}
?>
<div class="<?php echo $termsString ;?> flex-col-sm-4 item">
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<div class="post-featured-thumbnail">
<?php
if ( has_post_thumbnail() ) {
if($count == 1){
the_post_thumbnail('blog_featured');
}else{
the_post_thumbnail();
}
}
;
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
numgrade_category_sticker();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</div>
<div class="post-content">
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php echo excerpt($limit); ?>
</div><!-- .entry-content -->
</div>
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php
endwhile;
wp_reset_postdata();
endif;
die;
}
add_action('wp_ajax_ccfilter', 'cc_filter_function');
add_action('wp_ajax_nopriv_ccfilter', 'cc_filter_function');
function cc_filter_function(){
if( isset( $_POST['category_filters'] ) )
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $_POST['category_filters'],
"posts_per_page" => 5
)
);
query_posts( $args );
global $wp_query;
if( have_posts() ) : $count = (int)0;
ob_start();
while( have_posts() ): $count++;
the_post();
if($count == 1){
$span = 'flex-col-xs-12';
$limit = 20;
}
if($count == 2 || $count == 3){
$span = 'flex-col-sm-6';
$limit = 13;
}
if($count > 3){
$span = 'flex-col-sm-4';
$limit = 13;
}
$termsArray = get_the_terms($post->ID, "category");
$termsString ="";
foreach ( $termsArray as $term ) {
$termsString .= $term->slug;
}
?>
<div class="<?php echo $termsString .' ' . $span ;?> item">
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<div class="post-featured-thumbnail">
<?php
if ( has_post_thumbnail() ) {
if($count == 1){
the_post_thumbnail('blog_featured');
}else{
the_post_thumbnail();
}
}
;
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php
numgrade_category_sticker();
?>
</div><!-- .entry-meta -->
<?php endif; ?>
</div>
<div class="post-content">
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php echo excerpt($limit); ?>
</div><!-- .entry-content -->
</div>
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php
endwhile;
wp_reset_postdata();
$posts_html = ob_get_contents();
ob_end_clean();
else:
$posts_html = '<p>Nothing found for your criteria.</p>';
endif;
echo json_encode( array(
'posts' => json_encode( $wp_query->query_vars ),
'max_page' => $wp_query->max_num_pages,
'found_posts' => $wp_query->found_posts,
'content' => $posts_html
) );
die();
}
Then finaly, here is the js code in a separate js file
jQuery(function($){
/* LOAD MORE FUNCTION ON FORMATION ARCHIVE PAGE */
$('#cc_loadmore').click(function(){
$.ajax({
url : cc_loadmore_params.ajaxurl, // AJAX handler
data : {
'action': 'loadmorebutton', // the parameter for admin-ajax.php
'query': cc_loadmore_params.posts, // loop parameters passed by wp_localize_script()
'page' : cc_loadmore_params.current_page // current page
},
type : 'POST',
beforeSend : function ( xhr ) {
$('#cc_loadmore').text('Loading...'); // some type of preloader
},
success : function( posts ){
if( posts ) {
$('#cc_loadmore').text( 'More posts' );
$('#cc_posts_wrap').append( posts ); // insert new posts
cc_loadmore_params.current_page++;
if ( cc_loadmore_params.current_page == cc_loadmore_params.max_page )
$('#cc_loadmore').hide(); // if last page, HIDE the button
} else {
$('#cc_loadmore').hide(); // if no data, HIDE the button as well
}
}
});
return false;
});
/* FILTERING FUNCTION ON FORMATION ARCHIVE PAGE */
$('#post_filters').change(function(){
$.ajax({
url : cc_loadmore_params.ajaxurl,
data : $('#post_filters').serialize(), // form data
dataType : 'json', // this data type allows us to receive objects from the server
type : 'POST',
success : function( data ){
// when filter applied:
// set the current page to 1
cc_loadmore_params.current_page = 1;
// set the new query parameters
cc_loadmore_params.posts = data.posts;
// set the new max page parameter
cc_loadmore_params.max_page = data.max_page;
// change the button label back
// insert the posts to the container
$('#cc_posts_wrap').html(data.content);
// hide load more button, if there are not enough posts for the second page
if ( data.max_page < 2 ) {
$('#cc_loadmore').hide();
} else {
$('#cc_loadmore').show();
}
}
});
// do not submit the form
return false;
});
});

php href hyperlink to specific post

on my site, i have 4 "Program" names that link to the same page.
however instead, i want each program to link to a SPECIFIC POST.
BUT, in my php code, the names are and link are all controlled by one thing...this:
<h3 class="sub-title"> <?php the_title(); ?></h3>
if I change that href="http://questtkd.com/programs/" to href="?php the_post(); ?" will it break my site? or will that do the trick?
how do I change that href so that each sub-title will go to a specific post?
here is the code:
<?php
/**
* Practice Section.
*
* #package Lawyer_Landing_Page
*/
$section_title = get_theme_mod( 'pratice_section_page' );
$post_one = get_theme_mod( 'practice_post_one' );
$post_two = get_theme_mod( 'practice_post_two' );
$post_three = get_theme_mod( 'practice_post_three' );
$post_four = get_theme_mod( 'practice_post_four' );
$posts = array( $post_one, $post_two, $post_three, $post_four );
$posts = array_diff( array_unique( $posts ), array('') );
if( $section_title || $posts ){
?>
<section class="practice-area">
<div class="container">
<?php
lawyer_landing_page_get_section_header( $section_title );
$qry = new WP_Query( array(
'post_type' => array( 'post', 'page' ),
'posts_per_page' => -1,
'post__in' => $posts,
'orderby' => 'post__in',
'ignore_sticky_posts' => true
) );
if( $posts && $qry->have_posts() ){ ?>
<div class="row">
<?php
while( $qry->have_posts() ){
$qry->the_post(); ?>
<div class="col">
<div class="box">
<?php if( has_post_thumbnail() ){ ?>
<div class="icon-holder">
<?php the_post_thumbnail( 'lawyer-landing-page-practice' ); ?>
</div>
<?php } ?>
<div class="text-holder">
<h3 class="sub-title"> <?php the_title(); ?></h3>
<?php
the_excerpt();
?>
</div>
</div>
</div>
<?php
}
wp_reset_postdata(); ?>
</div>
<?php
}
?>
</div>

Can someone help me to add a category to this Post?

I'm using this code in different sections of my website and I want to display different posts in each section of the front page according to their category.
Can someone please help em to add a category there one is "surf" , I've tried everything.
Or maybe a different way to do it?
Thank you.
<div class="posts">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$total_post_count = wp_count_posts();
$published_post_count = $total_post_count->publish;
$total_pages = ceil( $published_post_count / $posts_per_page );
if ( "1" < $paged ) : ?>
<div class="page-title section small-padding">
<h4 class="section-inner"><?php printf( __('Page %s of %s', 'radcliffe'), $paged, $wp_query->max_num_pages ); ?></h4>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="archive-nav">
<?php echo get_next_posts_link( '« ' . __('Posts Antigos', 'radcliffe')); ?>
<?php echo get_previous_posts_link( __('Posts Recentes', 'radcliffe') . ' »'); ?>
<div class="clear"></div>
</div> <!-- /post-nav archive-nav -->
<?php endif; ?>
<?php endif; ?>
</div> </div> <!-- /posts -->
If you are trying to display category by ID , Then
global $post;
$args = array( 'category' => '12' );
$cat_post= get_posts( $args );
foreach( $cat_post as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
Note: In $args = array( 'category' => '12' ); 12 is the ID of
the category
But if you want to display category by Name, Then
global $post;
$args = array( 'category_name' => 'uncatogerized' );
$cat_post= get_posts( $args );
foreach( $cat_post as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
Here, uncategorized is a category name

Get posts all posts by Tag / URL Wordpress

I'm looking to create a tag.php page, which displays all tags when the user clicks on the tag from a tag cloud. This is what I've got so far, but this seems to display all of my posts.
<article class="articles">
<?php
echo '<h2>Tag:';
$tag = single_tag_title();
echo '</h2>';
$args = array(
'taxonomy' => $tag,
'terms' => $tag,
);
$postslist = get_posts( $args );?>
<?php foreach( $postslist as $post ) : setup_postdata($post); ?>
<div class="clear"></div>
<span class="timestamp"><?php echo mysql2date('j M Y', $post->post_date) ;?></span></h2>
<p class="about"><?php the_title(); ?></p>
<?php the_content(''); ?>
<?php endforeach;?>
</div>
I cannot seem to figure this out, I've been googling it but I can't seem to find out the information I want...
Your single_tag_title it's not returning to variable:
$tag = single_tag_title('', false);
try with:
<?php
$tag = single_tag_title('', false);
echo '<h2>Tag: '.$tag.'</h2>';
$args = array(
'taxonomy' => $tag,
'terms' => $tag,
);
$postslist = get_posts( $args );?>
<?php foreach( $postslist as $post ) : setup_postdata($post); ?>
<div class="clear"></div>
<span class="timestamp"><?php echo mysql2date('j M Y', $post->post_date) ;?></span></h2>
<p class="about"><?php the_title(); ?></p>
<?php the_content(); ?>
</div>
<?php endforeach;?>
Try using wp_query
$tag = single_tag_title('', false);
echo '<h2>Tag: '.$tag.'</h2>';
// The Query
$the_query = new WP_Query( $tag );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$post = get_queried_object();
echo "<div class='clear'></div>
<span class='timestamp'>" . mysql2date('j M Y', $post->post_date) . " </span></h2>
<p class='about'" . the_title() . "</p>";
<?php the_content(); ?>
</div>
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
Please note, I haven't tested this code!

Categories