I want to add a number navigation in order to browse through the posts.
In the home of my theme I have this code that shows the posts.
<div class="container mt-80 mb-80">
<div class="card-columns">
<?php $args['tax_query'] = array(
array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
);
query_posts($args);?>
<?php while(have_posts()) : the_post(); ?>
<div class="card">
<div class="card-body">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('full', array('class' => 'image-post card-img-top')); ?>
</a>
<h3 class="card-title"><?php the_title(); ?></h3>
<p class="card-text"><?php echo get_the_excerpt(); ?> ...</p>
<span class="entry-date"><?php echo get_the_date(); ?></span>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
To show the pagination I tried to add this code on the function.php
I want to insert the page numbers below the posts to browse them but I don't want to install any plugins.
function numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n"; }
And this on the index.php
<?php numeric_posts_nav(); ?>
The navigation appears but does not work properly. Does anyone know why?
put below code in function.php file
function pagination_nav() {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) { ?>
<nav class="pagination" role="navigation">
<div class="nav-previous"><?php next_posts_link( '← Older posts' ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts →' ); ?></div>
</nav>
}
}
and this code in index.php file :
pagination_nav();
Add below thing in the argument
$args = array(
'post_per_page' => 10,
'paged'=> 'paged', //'paged' for the home page and for other pages we need to set 'page',
'tax_query'=> array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
);
And add the function just after your loop ends
<?php numeric_posts_nav(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'post_per_page' => 10,
'paged'=> $paged,
'tax_query'=> array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
); ?>
<?php $wp_query = new WP_Query($args); ?>
<?php if ($wp_query->have_posts()) : ?>
<?php while ( $wp_query -> have_posts() ) : $wp_query->the_post(); ?>
// Post content goes here...
<?php endwhile; ?>
<?php numeric_posts_nav(); ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
Related
In my custom post type archive page, I would like to be able to filter posts by categories.
I have achieved this, but I can only manage to display all categories. I would like same level categories below the current category to be visible only.
For example if I have taxonomies like :
Category 1
-- Subcategory 1
--- subsub 1.1
-- Subcategory 2
When I am on the page https://example.com/mycpt/?getby=cat&cat=category-1
Only Subcategories 1 and Subcategory 2 should be visible
Here is my code:
In archive-mycpt.php
<div class="filter-custom-taxonomy">
<?php
$terms = get_terms( ['taxonomy' => 'product_cat'] );
foreach ( $terms as $term ) : ?>
<a href="<?php echo home_url() ?>/tutos/?getby=cat&cat=<?php echo esc_attr( $term->slug ); ?>">
<?php echo esc_html( $term->name ); ?>
</a>
<?php endforeach; ?>
</div>
<div class="row">
<div class="small-12 columns">
<?php do_action( 'thb_archive_title' ); ?>
<div class="row">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
get_template_part( 'inc/templates/post-styles/post-style1' );
endwhile;
endif;
?>
</div>
<?php
the_posts_pagination(
array(
'prev_text' => '',
'next_text' => '',
'mid_size' => 2,
)
);
?>
</div>
</div>
and in function.php
function kbites_words_filter_archive( $query ) {
if ( ! $query->is_main_query() )
return $query;
if ( is_admin() ) {
return;
}
if ( is_post_type_archive('tutos') ) {
if (isset($_GET['getby'])) {
if ( 'cat' === $_GET['getby'] ) {
$taxquery = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $_GET['cat'],
),
);
$query->set( 'tax_query', $taxquery );
}
}
$query->set( 'posts_per_page', 30 );
}
return $query;
}
add_action( 'pre_get_posts', 'kbites_words_filter_archive');
I have a custom post type 'charters' and within my category.php page I have a loop pulling in 'charter' posts for the current category id. I have a custom pagination setup displaying page numbers when I click page 2 link, it goes to URL /page/2 which displays a 404 error. I can't figure out why I am getting the 404. If I adjust my posts per page the pagination updates and displays the correct number of pages but the links do not show up.
Category.php Code:
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$product_args = array(
'post_type' => 'charters',
'posts_per_page' => 10, //the same as the parse_query filter in our functions.php file
'paged' => $paged,
'page' => $paged,
'cat' => $cat
);
$product_query = new WP_Query( $product_args ); ?>
<?php if ( $product_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $product_query->have_posts() ) : $product_query->the_post(); ?>
<article class="loop">
<h3><?php the_title(); ?></h3>
<div class="content">
<?php the_excerpt(); ?>
</div>
</article>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php
if (function_exists( 'custom_pagination' )) :
custom_pagination( $product_query->max_num_pages,"",$paged );
endif;
?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Functions.php Code:
function prefix_change_cpt_archive_per_page( $query ) {
//* for cpt or any post type main archive
if ( $query->is_main_query() && ! is_admin() && is_post_type_archive( 'product' ) ) {
$query->set( 'posts_per_page', '10' );
}
}
add_action( 'pre_get_posts', 'prefix_change_cpt_archive_per_page' );
function prefix_change_category_cpt_posts_per_page( $query ) {
if ( $query->is_main_query() && ! is_admin() && is_category( 'test-category' ) ) {
$query->set( 'post_type', array( 'product' ) );
$query->set( 'posts_per_page', '2' );
}
}
add_action( 'pre_get_posts', 'prefix_change_category_cpt_posts_per_page' );
function custom_pagination( $numpages = '', $pagerange = '', $paged='' ) {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
My Permalink Settings are set to "Post Name" I have a feeling this has something to do with rewrites but I can not figure out how to get the page urls to work correctly. An example of my categories are as follows:
/category/long-beach/
/category/san-diego/
you should try this:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'charters',
'cat'=> $cat,
'post_per_page'=> 6,
'paged' => $paged
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><?php the_title(); ?></p><?php
endwhile;
}
wp_reset_query();
?>
<?php echo pnavigation( $query ); ?>
then you need to add following code to function.php :
function pnavigation( $wp_query ) {
$big = 999999999; // need an unlikely integer
$pages = 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_next' => false,
'type' => 'array',
'prev_next' => TRUE,
'prev_text' => '←',
'next_text' => '→',
) );
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<ul class="pagination pagination-lg">';
foreach ( $pages as $page ) {
echo "<li>$page</li>";
}
echo '</ul>';
}
}
you need to just replace url (client-testimonials) with your url
function pagination_rewrite() {
add_rewrite_rule('client-testimonials/page/?([0-9]{1,})/?$', 'index.php?pagename=client-testimonials&paged=$matches[1]', 'top');
}
add_action('init', 'pagination_rewrite');
If you are using default pagination then please use below code.
<?php
$current_page = get_queried_object();
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'charters',
'paged' => $paged,
'cat'=> $cat);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><?php the_title(); ?></p><?php
endwhile;
}
next_posts_link( 'Older Entries', $my_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
wp_reset_query();
?>
Add below code in your function.php
function posts_on_categorypage( $query ) {
if ( $query->is_category()) {
$query->set( 'posts_per_page', '10' );
}
}
add_action( 'pre_get_posts', 'posts_on_categorypage' );
There was a couple of errors in my code. This is what I get for copy/pasting code and not going through it line by line. Thanks everyone who helped out, but I got this to work by changing:
Bad Code:
function prefix_change_category_cpt_posts_per_page( $query ) {
if ( $query->is_main_query() && ! is_admin() && is_category( 'test-category' ) ) {
$query->set( 'post_type', array( 'product' ) );
$query->set( 'posts_per_page', '2' );
}
}
Good Code:
function prefix_change_category_cpt_posts_per_page( $query ) {
if ( $query->is_main_query() && ! is_admin() && is_category( $cat ) ) {
$query->set( 'post_type', array( 'charters' ) );
$query->set( 'posts_per_page', '10' );
}
}
So I am using WordPress with an underscores theme. I used code from twenty fourteen's theme with pagination.
if ( ! function_exists( 'public_notices_paging_nav' ) ) :
function public_notices_paging_nav() {
global $wp_query, $wp_rewrite;
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages < 2 ) {
echo ("<h4 class='one-page-results'>End of Results</h4>");
return;
}
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
$pagenum_link = html_entity_decode( get_pagenum_link() );
$query_args = array();
$url_parts = explode( '?', $pagenum_link );
if ( isset( $url_parts[1] ) ) {
wp_parse_str( $url_parts[1], $query_args );
}
$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
// Set up paginated links.
$links = paginate_links( array(
'base' => $pagenum_link,
'format' => $format,
'total' => $wp_query->max_num_pages,
'current' => $paged,
'mid_size' => 1,
'add_args' => array_map( 'urlencode', $query_args ),
'prev_text' => __( '← Previous', 'public_notices' ),
'next_text' => __( 'Next →', 'public_notices' ),
'type' => 'list',
) );
if ( $links ) :
?>
<nav class="navigation paging-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'public_notices' ); ?></h1>
<?php echo $links; ?>
</nav><!-- .navigation -->
<?php
endif;
}endif;
This worked great when I only had one post type, but now I've made a loop that displays two post types and it works. But on every page its the same group of posts.
<?php
$postLoop = array(
'post_type' => array('public_notice_post', 'post'),
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query( $postLoop );
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
public_notices_paging_nav();
endif;
wp_reset_query(); ?>
Anything will help. I've tried a lot.
Maybe you got a loop with no "wp_reset_query()" and this may caused some bugs on other loop.. just look all your loop to be sure there noone without reset query.
On which kind of page you coded this loop ? This is a custom template or other ?
Sorry for my english, im french.
To fix the original problem of duplicated posts on every page all I had to do was write my code like this. HOWEVER I am still having an issue of page count, but that will addressed elsewhere.
<?php
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$ppp = get_option( 'posts_per_page' );
if ( $page == 1 )
$offset = 6;
else
$offset = 6 + ( $page - 1 ) * $ppp;
?>
<?php
$postLoop = array(
'post_type' => array('public_notice_post', 'post'),
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page'=> $ppp,
'offset' => $offset
);
$wp_query = new WP_Query( $postLoop );
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
public_notices_paging_nav();
endif;
wp_reset_query(); ?>
I am useing wp- simple page navigation plugin and my code in template for navigation is given below
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'product', 'posts_per_page' => 6, 'product_cat' => '', 'orderby' => 'rand' , 'paged' => $page );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<div class="view view-eighth">
<?php echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog', array(
'style' => 'width: 243px; height: 323px;'
)); ?>
<div class="mask">
<div class="product_name"><?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?></div>
<div class="price">
<span><?php echo get_woocommerce_currency_symbol(); ?></span><?php echo get_post_meta( get_the_ID(), '_regular_price', true); //$product->get_price_html(); ?></div>
<div class="add_to_cart_btn">
Add to cart
</div>
<div class="details">View Details</div>
</div>
</div>
<?php endwhile; wp_simple_pagination(); wp_reset_query(); ?>
My pagination showing but when i click on page number its not working
Any idea help greatly appreciated
Thanks
In advance
Place the below custom pagination function in your theme's functions.php file, then call the function on page, where you want the pagination to appear, like this
if (function_exists('_numeric_posts_nav')) {_numeric_posts_nav();}:
/********* CUSTOM PAGINATION ***********/
if (!function_exists('_numeric_posts_nav')) {
function _numeric_posts_nav() {
global $wp_query;
/** Stop execution if there's if it is single past/page or only 1 page */
if( is_singular() ) return;
if( $wp_query->max_num_pages <= 1 ) return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation clearfix"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
}
That's it. You do not need a special plugin of pagination anymore and all links will work.
Optionally you can set different CSS classes inside the function.
I was translating the titles and sentences right on the editor. I don't know what went wrong, but when I hit upload I keep getting this:
Parse error: syntax error, unexpected 'Comentários' (T_STRING) in /home2/tkleinow/public_html/wp-content/themes/fashionistas/inc/template-tags.php on line 94
Then I tried to copy the original code for that section (template tags) on the zip files, but I keep getting the same error.
I pasted it on Excel to find what the line was, and this is wat I got:
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
My website was doing just fine, I don't know how I screwed it like that.
This is the whole thing:
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features
*
* #package aThemes
*/
if ( ! function_exists( 'athemes_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function athemes_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'athemes' ); ?></h1>
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php previous_post_link( '<div class="nav-previous"><span>Artigo Anterior</span>%link</div>', '<span class="meta-nav">' . _x( '←', 'Link do Post Anterior', 'athemes' ) . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next"><span>Próximo Artigo</span>%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Link para o próximo artigo', 'athemes' ) . '</span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Artigos Anteriores', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Artigos Recentes <span class="meta-nav">→</span>', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}
endif; // athemes_content_nav
if ( ! function_exists( 'athemes_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*/
function athemes_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<div class="comment-body">
<?php _e( 'Pingback:', 'athemes' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'athemes' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<?php else : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="clearfix comment-meta">
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<div class="clearfix comment-author vcard">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<div class="comment-metadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>">
<?php printf( _x( '%1$s', '1: date, 2: time', 'athemes' ), get_comment_date(), get_comment_time() ); ?>
</time>
</a>
</div><!-- .comment-metadata -->
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Seu comentário será aprovado assim que passar pela moderação.', 'athemes' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
</article><!-- .comment-body -->
<?php
endif;
}
endif; // ends check for athemes_comment()
if ( ! function_exists( 'athemes_the_attached_image' ) ) :
/**
* Prints the attached image with a link to the next attached image.
*/
function athemes_the_attached_image() {
$post = get_post();
$attachment_size = apply_filters( 'athemes_attachment_size', array( 1200, 1200 ) );
$next_attachment_url = wp_get_attachment_url();
/**
* Grab the IDs of all the image attachments in a gallery so we can get the
* URL of the next adjacent image in a gallery, or the first image (if
* we're looking at the last image in a gallery), or, in a gallery of one,
* just the link to that image file.
*/
$attachment_ids = get_posts( array(
'post_parent' => $post->post_parent,
'fields' => 'ids',
'numberposts' => -1,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
// If there is more than 1 attachment in a gallery...
if ( count( $attachment_ids ) > 1 ) {
foreach ( $attachment_ids as $attachment_id ) {
if ( $attachment_id == $post->ID ) {
$next_id = current( $attachment_ids );
break;
}
}
// get the URL of the next image attachment...
if ( $next_id )
$next_attachment_url = get_attachment_link( $next_id );
// or get the URL of the first image attachment.
else
$next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
}
printf( '%3$s',
esc_url( $next_attachment_url ),
the_title_attribute( array( 'echo' => false ) ),
wp_get_attachment_image( $post->ID, $attachment_size )
);
}
endif;
if ( ! function_exists( 'athemes_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function athemes_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
//if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
//$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span>', 'athemes' ),
sprintf( '%3$s',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
}
endif;
/**
* Returns true if a blog has more than 1 category
*/
function athemes_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so athemes_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so athemes_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in athemes_categorized_blog
*/
function athemes_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'athemes_category_transient_flusher' );
add_action( 'save_post', 'athemes_category_transient_flusher' );