I need to shorten the title in the previous and next buttons in a WP theme.
Here's the code:
<?php
/* ----------------------------------------------------------------------------------
Display navigation to next/previous pages when applicable.
---------------------------------------------------------------------------------- */
if ( ! function_exists( 'thinkup_input_nav' ) ) :
function thinkup_input_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 role="navigation" id="<?php echo $nav_id; ?>">
<?php if ( is_single() ) : ?>
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">%title</span>' ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '<span class="meta-nav">%title</span><span class="meta-icon"><i class="icon-angle-right icon-large"></i></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( __( 'Older posts', 'lan-thinkupthemes') ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'lan-thinkupthemes') ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo $nav_id; ?> -->
<?php
}
endif;
/* ----------------------------------------------------------------------------------
Display navigation to next/previous image when applicable.
---------------------------------------------------------------------------------- */
if ( ! function_exists( 'thinkup_input_imagesnav' ) ) :
function thinkup_input_imagesnav() {
global $wp_query, $post;
?>
<nav role="navigation" id="nav-below">
<div class="nav-previous"><?php previous_image_link( 'false', '<div class="nav-previous"><span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">' . __( 'Previous', 'lan-thinkupthemes') . ' </span></div>' ); ?></div>
<div class="nav-next"><?php next_image_link( 'false', '<span class="meta-nav">' . __( 'Next', 'lan-thinkupthemes') . '</span><span class="meta-icon"><i class="icon-angle-right icon-large"></i></span>' ); ?></div>
</nav><!-- #image-navigation -->
<?php
}
endif;
/* Display comments at bottom of post, page and project pages. */
function thinkup_input_allowcomments() {
if ( comments_open() || '0' != get_comments_number() )
comments_template( '/comments.php', true );
}
/* ----------------------------------------------------------------------------------
Returns true if a blog has more than 1 category.
---------------------------------------------------------------------------------- */
function thinkup_input_categorizedblog() {
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 ) {
return true;
} else {
return false;
}
}
/* Flush out the transients used in thinkup_input_categorizedblog. */
function thinkup_input_transient_flusher() {
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'thinkup_input_transient_flusher' );
add_action( 'save_post', 'thinkup_input_transient_flusher' );
What I tried was to add substring to this line:
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav">%title</span>' ); ?>
to:
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-icon"><i class="icon-angle-left icon-large"></i></span><span class="meta-nav"><?php echo substr(%title,0,10)?></span>' ); ?>
but upon reloading the page it displayed an empty text instead.
What am I doing wrong?
You can override the previous_post_link() function in your functions.php file of your theme as like this :
function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '',$limit = -1) {
if ( is_attachment() )
$post = & get_post($GLOBALS['post']->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories);
if ( !$post )
return;
$title = apply_filters('the_title', $post->post_title, $post);
if ($limit>-1) {$title = substr($title,0,$limit).'…';}
$string = '<a href="'.get_permalink($post->ID).'">';
$link = str_replace('%title', $title, $link);
$link = $pre . $string . $link . '</a>';
$format = str_replace('%link', $link, $format);
echo $format;
And then you can call the function with the additional argument to define your desired trim length:
<li><?php previous_post_link('%link','« %title',FALSE,'',20); ?></li>
Hope it helps you.
Taken from https://wordpress.org/support/topic/using-substr-to-limit-characters-in-post-title
Related
My navigation stoped working on my custompost category... i have this :
Portfolio
<?php $loop = new WP_Query( array( 'post_type' => 'portfolios', 'posts_per_page' => 8, 'offset'=> 0 ,'paged' => $paged, ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li class="list_c">
<a href="<?php the_permalink(); ?>"><div><div id="over2"><p>+info</p></div></div>
<div id="read"> <span>ler mais </span></div>
<div id="ptxL" class="filldiv">
<div id="thumbL" class="grow "><?php the_post_thumbnail('featuredImageCropped3');?></div>
<div id="infoL">
<div id="titled" class="tt">
<h2><?php the_title();?></h2></div>
<div id="contentL"><h3><?php the_excerpt(); ?> </h3></div></div><div id="color"></div>
<!-- You have not associated any custom fields with this post-type. Be sure to add any desired custom fields to this post-type by clicking on the "Manage Custom Fields" link under the Custom Content Type menu and checking the fields that you want. -->
</div></a></li>
<?php endwhile; wp_reset_query(); ?>
<?php wpbeginner_numeric_posts_nav(); ?>
<?php get_footer(); ?>
and on my functions.php:
function wpbeginner_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 class="pre">%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";
}
i changed servers maybe thats the problem...but i can make it work...my debug finds no errors...
Please try this code.I think you have mistake in paged parameter.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'portfolios', 'posts_per_page' => 8, 'offset'=> 0 ,'paged'=>$paged ) ); ?>
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li class="list_c">
<a href="<?php the_permalink(); ?>"><div><div id="over2"><p>+info</p></div></div>
<div id="read"> <span>ler mais </span></div>
<div id="ptxL" class="filldiv">
<div id="thumbL" class="grow "><?php the_post_thumbnail('featuredImageCropped3');?></div>
<div id="infoL">
<div id="titled" class="tt">
<h2><?php the_title();?></h2></div>
<div id="contentL"><h3><?php the_excerpt(); ?> </h3></div></div><div id="color"></div>
<!-- You have not associated any custom fields with this post-type. Be sure to add any desired custom fields to this post-type by clicking on the "Manage Custom Fields" link under the Custom Content Type menu and checking the fields that you want. -->
</div></a></li>
<?php endwhile;endif; ?>
<?php wpbeginner_numeric_posts_nav(); ?>
<?php wp_reset_query(); ?>
I hope this will work for you.
Thanks
I'm using the Avada theme in wordpress. I'm trying to add some post custom fields into the scrollover (shown by mouse hover). I tried to edit the template file that controls the scrollover but without success. I got an error message invalid ">".
I tried to use this code to show the custom field:
<?php echo get_post_meta( $post_id,'the_price',); ?>
The Avada function template is as follows:
if ( ! function_exists( 'avada_render_rollover' ) ) {
function avada_render_rollover( $post_id, $post_permalink = '', $display_woo_price = false, $display_woo_buttons = false, $display_post_categories = 'default', $display_post_title = 'default', $gallery_id = '' ) {
// Retrieve the permalink if it is not set
if ( ! $post_permalink ) {
$post_permalink = get_permalink( $post_id );
}
// Check if theme options are used as base or if there is an override for post categories
if ( 'enable' == $display_post_categories ) {
$display_post_categories = true;
} elseif ( 'disable' == $display_post_categories ) {
$display_post_categories = false;
} else {
$display_post_categories = ! Avada()->settings->get( 'cats_image_rollover' );
}
// Check if theme options are used as base or if there is an override for post title
if ( 'enable' == $display_post_title ) {
$display_post_title = true;
} elseif ( 'disable' == $display_post_title ) {
$display_post_title = false;
} else {
$display_post_title = ! Avada()->settings->get( 'title_image_rollover' );
}
// Set the link on the link icon to a custom url if set in page options
$icon_permalink = ( fusion_get_page_option( 'link_icon_url', $post_id ) != null ) ? fusion_get_page_option( 'link_icon_url', $post_id ) : $post_permalink;
if ( '' == fusion_get_page_option( 'image_rollover_icons', $post_id ) || 'default' == fusion_get_page_option( 'image_rollover_icons', $post_id ) ) {
if( ! Avada()->settings->get( 'link_image_rollover' ) && ! Avada()->settings->get( 'zoom_image_rollover' ) ) { // link + zoom
$image_rollover_icons = 'linkzoom';
} elseif( ! Avada()->settings->get( 'link_image_rollover' ) && Avada()->settings->get( 'zoom_image_rollover' ) ) { // link
$image_rollover_icons = 'link';
} elseif( Avada()->settings->get( 'link_image_rollover' ) && ! Avada()->settings->get( 'zoom_image_rollover' ) ) { // zoom
$image_rollover_icons = 'zoom';
} elseif( Avada()->settings->get( 'link_image_rollover' ) && Avada()->settings->get( 'zoom_image_rollover' ) ) { // link
$image_rollover_icons = 'no';
} else {
$image_rollover_icons = 'linkzoom';
}
} else {
$image_rollover_icons = fusion_get_page_option( 'image_rollover_icons', $post_id );
}
// Set the link target to blank if the option is set
$link_target = ( 'yes' == fusion_get_page_option( 'link_icon_target', $post_id ) || 'yes' == fusion_get_page_option( 'post_links_target', $post_id ) ) ? ' target="_blank"' : '';
?>
<div class="fusion-rollover">
<div class="fusion-rollover-content">
<?php if ( 'no' != $image_rollover_icons && 'product' != get_post_type( $post_id ) ) : // Check if rollover icons should be displayed ?>
<?php if ( 'zoom' != $image_rollover_icons ) : // If set, render the rollover link icon ?>
<a class="fusion-rollover-link" href="<?php echo $icon_permalink; ?>"<?php echo $link_target; ?>>Permalink</a>
<?php endif; ?>
<?php if ( 'link' != $image_rollover_icons ) : // If set, render the rollover zoom icon ?>
<?php
// Get the image data
$full_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'full' );
if ( ! is_array( $full_image ) ) {
$full_image = array();
$full_image[0] = '';
}
// If a video url is set in the post options, use it inside the lightbox
if ( fusion_get_page_option( 'video_url', $post_id ) ) {
$full_image[0] = fusion_get_page_option( 'video_url', $post_id );
}
?>
<?php if ( 'linkzoom' == $image_rollover_icons || '' === $image_rollover_icons ) : // If both icons will be shown, add a separator ?>
<div class="fusion-rollover-sep"></div>
<?php endif; ?>
<?php if ( $full_image[0] ) : // Render the rollover zoom icon if we have an image ?>
<?php
// Only show images of the clicked post
if ( 'individual' == Avada()->settings->get( 'lightbox_behavior' ) ) {
$lightbox_content = avada_featured_images_lightbox( $post_id );
$data_rel = sprintf( 'iLightbox[gallery%s]', $post_id );
// Show the first image of every post on the archive page
} else {
$lightbox_content = '';
$data_rel = sprintf( 'iLightbox[gallery%s]', $gallery_id );
}
?>
<a class="fusion-rollover-gallery" href="<?php echo $full_image[0]; ?>" data-id="<?php echo $post_id; ?>" data-rel="<?php echo $data_rel; ?>" data-title="<?php echo get_post_field( 'post_title', get_post_thumbnail_id( $post_id ) ); ?>" data-caption="<?php echo get_post_field( 'post_excerpt', get_post_thumbnail_id( $post_id ) ); ?>">Gallery</a><?php echo $lightbox_content; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ( $display_post_title ) : // Check if we should render the post title on the rollover ?>
<h4 class="fusion-rollover-title"><a href="<?php echo $icon_permalink; ?>"<?php echo $link_target; ?>><?php echo get_the_title( $post_id ); ?></a></h4>
<?php endif; ?>
<?php
// Check if we should render the post categories on the rollover
if ( $display_post_categories ) {
// Determine the correct taxonomy
if ( 'post' == get_post_type( $post_id ) ) {
$post_taxonomy = 'category';
} elseif ( 'avada_portfolio' == get_post_type( $post_id ) ) {
$post_taxonomy = 'portfolio_category';
} elseif ( 'product' == get_post_type( $post_id ) ) {
$post_taxonomy = 'product_cat';
}
echo get_the_term_list( $post_id, $post_taxonomy, '<div class="fusion-rollover-categories">', ', ', '</div>' );
}
?>
<?php if ( $display_woo_price ) : // Check if we should render the woo product price ?>
<?php woocommerce_get_template( 'loop/price.php' ); ?>
<?php endif; ?>
<?php if ( $display_woo_buttons ) : // Check if we should render the woo "add to cart" and "details" buttons ?>
<div class="fusion-product-buttons">
<?php woocommerce_get_template( 'loop/add-to-cart.php' ); ?>
<span class="fusion-rollover-linebreak"></span>
<a class="fusion-show-details-button" href="<?php echo post_permalink(); ?>"><?php _e( 'Details', 'Avada' ); ?></a>
</div>
<?php endif; ?>
</div>
</div>
<?php
}
}
Usually to use $post_id you need first to declare global $post
I am trying to insert google ads between every 7th posts in my wordpress site with infinite scroll. i searched and found results but that didn't worked for me because the WordPress theme i am using is little complex. the result i found was to add this code
<?php $postnum++; if($postnum%5 == 0) { ?>
YOUR AD CODE HERE
<?php } ?>
after <?php endwhile; ?> in index.php, but in my case the loop is different from the general wordpress theme. the loop i have is like this and i want to know how can i implement the above code in my case.
loop code
static function loop( $template ) {
global $wp_query;
echo '<input type="hidden" id="query-' . $template . '" value="' . urlencode( json_encode( $wp_query -> query ) ) . '" />';
if ( count( $wp_query->posts) > 0 ) {
if( self::is_grid( $template ) ){
?>
<div class="loop-container-view grid">
<?php self::loop_switch( $template , 1 ); ?>
</div>
<?php
}else{
?>
<div class="loop-container-view list" id="contloop">
<?php self::loop_switch( $template , 0 ); ?>
</div>
<?php
}
get_template_part('pagination');
} else {
get_template_part('loop', '404');
}
}
which then call this code, i made it a little shorter
static function get( $post , $template = 'blog_page' ){
$meta = meta::get_meta( $post -> ID , 'settings' );
if( isset( $meta['safe'] ) ){
if( meta::logic( $post , 'settings' , 'safe' ) ){
$classes = ' nsfw';
}else{
$classes = ' ';
}
}else{
$classes = ' ';
}
?>
<!-- post -->
<article id="post-<?php echo $post -> ID; ?>" <?php post_class( 'post ' . $classes , $post -> ID ); ?>>
</article>
<?php
}
loop switch function
static function loop_switch( $template = '' , $grid = 1 ) {
global $wp_query;
if ( !empty( $template ) ) {
$ajax = false;
} else {
$query = array();
$template = isset( $_POST['template'] ) && strlen( $_POST['template'] ) ? $_POST['template'] : exit();
$query = isset( $_POST['query'] ) && !empty( $_POST['query'] ) ? (array)json_decode( urldecode( $_POST['query'] ) ) : exit();
$query['post_status'] = 'publish';
$wp_query = new WP_Query( $query );
$grid = isset($_POST['grid']) ? (int)$_POST['grid'] : 1;
$ajax = true;
}
$template = str_replace( array( '_hot' , '_new' , '_like' ) , '' , $template );
if( $grid == 1 ){
$k = 1;
$i = 1;
$nr = $wp_query->post_count;
if (layout::get_length(0, $template) == 940 ) {
$div = 3;
} else {
$div = 2;
}
foreach ($wp_query->posts as $post) {
$wp_query->the_post();
if ($i == 1) {
if (( $nr - $k ) < $div) {
$classes = 'class="last"';
} else {
$classes = '';
}
echo '<div ' . $classes . '>';
}
self::grid( $post, $template );
if ($i % $div == 0) {
echo '</div>';
$i = 0;
}
$i++;
$k++;
}
if ($i > 1) {
echo '</div>';
}
}else{
foreach( $wp_query->posts as $index => $post ) {
$wp_query->the_post();
if ($index > 0) {
?><!--<p class="delimiter"> </p>--><?php
}
self::get( $post, $template );
}
}
if( $ajax ){
exit();
}
}
and post is called here in front-page.php file
<?php
$wp_query = new WP_Query(array( 'page_id' => options::get_value( 'front_page' , 'page' ) ) );
if( $wp_query -> post_count > 0 ){
foreach( $wp_query -> posts as $post ){
$wp_query -> the_post();
$post_id = $post -> ID;
?>
<article id="post-<?php the_ID(); ?>" <?php post_class() ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<!-- post meta top -->
<?php
if( meta::logic( $post , 'settings' , 'meta' ) ){
get_template_part( 'post-meta-top' );
}
?>
</header>
<div class="entry-content">
<?php
/* if show featured image */
if( options::logic( 'blog_post' , 'show_featured' ) ){
if( has_post_thumbnail ( $post -> ID ) ){
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post -> ID ) , 'full' );
?>
<div class="featimg circle">
<div class="img">
<?php
ob_start();
ob_clean();
get_template_part( 'caption' );
$caption = ob_get_clean();
?>
<?php the_post_thumbnail( '600x200' ); ?>
<?php
if( strlen( trim( $caption) ) ){
?>
<p class="wp-caption-text"><?php echo $caption; ?></p>
<?php
}
?>
</div>
</div>
<?php
}
}
?>
</div>
<footer class="entry-footer">
<div class="share">
<?php get_template_part( 'social-sharing' ); ?>
</div>
<div class="excerpt">
<?php the_content(); ?>
<?php wp_link_pages(); ?>
</div>
</footer>
</article>
<?php
}
}else{
/* not found page */
get_template_part( 'loop' , '404' );
}
Try this in front-page.php. You may have to adjust it to add after correct number of posts.
if( $wp_query -> post_count > 0 ){
$postnum = 0;
foreach( $wp_query -> posts as $post ){
$postnum++;
if( $postnum%5 == 0 ) {
echo '<p> ---- insert ad here ---- </p>';
}
$wp_query -> the_post();
$post_id = $post -> ID;
?>
it should replace this bit of code
if( $wp_query -> post_count > 0 ){
foreach( $wp_query -> posts as $post ){
$wp_query -> the_post();
$post_id = $post -> ID;
?>
I am trying to code a function for Wordpress Post navigation but i am getting
Trying to get property of non object
error in lines with $prevpost->ID and $nextpost->ID, the code is this:
if ( ! function_exists( 'mm_post_nav' ) ) :
/**
* Displays navigation to next/previous post when applicable.
*
* #since 1.0
*
* #return void
*/
function mm_post_nav() {
global $post;
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
$prevpost = get_previous_post(true);
$prevThumbnail = get_the_post_thumbnail($prevpost->ID, array(44,44) );
$nextpost = get_next_post(true);
$nextThumbnail = get_the_post_thumbnail($nextpost->ID, array(44,44) );
if ( ! $next && ! $previous )
return;
?>
<nav class="mm-post-nav" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'mm-cube' ); ?></h1>
<div class="mm-single-nav">
<div class="mm-prev-link">
<?php previous_post_link( '%link', _x( '<i class="icon-chevron-left"></i><span class="mm-prev-post-title"> %title</span>', 'Previous post link', 'mm-cube' ) ); ?>
</div>
<div class="mm-next-link">
<?php next_post_link( '%link', _x( '<span class="mm-next-post-title">%title</span><i class="icon-chevron-right"></i>' , 'Next post link', 'mm-cube' ) ); ?>
</div>
</div><!-- .nav-links -->
<div class="clear"></div>
</nav><!-- .navigation -->
<?php
}
endif;
Making a var_dump($prevpost) outputs this:
string(0) ""
You may try something like following, because $prevpost and $nextpost could return empty/null if there is no matching posts are available.
$prevpost = get_previous_post(true);
if (!empty( $prevpost )) {
$prevThumbnail = get_the_post_thumbnail($prevpost->ID, array(44,44) );
}
$nextpost = get_next_post(true);
if (!empty( $nextpost )) {
$nextThumbnail = get_the_post_thumbnail($nextpost->ID, array(44,44) );
}
Return Values (get_previous_post and get_next_post)
Post object if successful.
Null if global $post is not set.
Empty string if no corresponding post exists.
Read more on Codex about get_previous_post and get_next_post to know how they work and what they return on any condition.
Update: Check the function's arguments, you have used (in both previous and next):
previous_post_link( $format, $link, $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' );
You should use:
previous_post_link( '%link', _x( '<i class="icon-chevron-left"></i><span class="mm-prev-post-title">%title</span>', FALSE, 'mm-cube' ) );
Use same order for other function. Check more on Codex about previous_post_link and next_post_link
This is the actual code for the loop:
<div id="content" class="span9" role="main">
<?php if ( have_posts() ){
// Do we have any posts in the databse that match our query?
?>
<?php
get_template_part( 'inc/post-format/single', get_post_format() );
$enable_rtl = of_get_option('enable_rtl', false);
if(!of_get_option('disable_pagination')){
if($enable_rtl){
$next_post = get_adjacent_post( false, '', true );
$prev_post = get_adjacent_post( false, '', false );
}else{
$next_post = get_adjacent_post( false, '', false );
$prev_post = get_adjacent_post( false, '', true );
}
?>
<?php
}
// show related posts by tag
if(!of_get_option('disable_related_posts')){
get_template_part( 'inc/related-posts' );
}
endwhile; // OK, let's stop the post loop once we've displayed it
// If comments are open or we have at least one comment, load up the default comment template provided by Wordpress
if ( comments_open() )
comments_template( '', true );
}else{ // Well, if there are no posts to display and loop through, let's apologize to the reader (also your 404 error) ?>
<article class="post error">
<h1 class="404"><?php _e('Page not found', 'outbox'); ?></h1>
</article>
<?php } // OK, I think that takes care of both scenarios (having a post or not having a post to show) ?>
</div><!-- #content .site-content -->
This is the snippet which I want to add:
// Parent CPT
if ( 'cpt-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Normal loop markup
endwhile; endif;
}
// Child CPT
else if ( 'cpt-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
// Grandchild CPT
else if ( 'cpt-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
}
This is how I added it inside my actual code:
<div id="content" class="span9" role="main">
<?php if ( 'cpt-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'inc/post-format/single', get_post_format() );
endwhile; endif;
}
// Child CPT
else if ( 'cpt-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
// Grandchild CPT
else if ( 'cpt-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
}
?>
<?php
$enable_rtl = of_get_option('enable_rtl', false);
if(!of_get_option('disable_pagination')){
if($enable_rtl){
$next_post = get_adjacent_post( false, '', true );
$prev_post = get_adjacent_post( false, '', false );
}else{
$next_post = get_adjacent_post( false, '', false );
$prev_post = get_adjacent_post( false, '', true );
}
?>
<?php
}
// show related posts by tag
if(!of_get_option('disable_related_posts')){
get_template_part( 'inc/related-posts' );
}
endwhile; // OK, let's stop the post loop once we've displayed it
// If comments are open or we have at least one comment, load up the default comment template provided by Wordpress
if ( comments_open() )
comments_template( '', true );
}else{ // Well, if there are no posts to display and loop through, let's apologize to the reader (also your 404 error) ?>
<article class="post error">
<h1 class="404"><?php _e('Page not found', 'outbox'); ?></h1>
</article>
<?php } // OK, I think that takes care of both scenarios (having a post or not having a post to show) ?>
</div><!-- #content .site-content -->
And I'm getting this error: P**arse error: syntax error, unexpected T_ENDWHILE** in this line: endwhile;
I'm sure is something wrong on how I added the code but it's very confusing for me because the actual code has a lot of php tags around...
Any suggestion? Thanks!
i have changed ,try below code
<div id="content" class="span9" role="main">
<?php if ( 'cpt-parent' == wpse121567_get_cpt_hierarchy() ) {
// Normal loop here
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'inc/post-format/single', get_post_format() );
endwhile; endif;
}
// Child CPT
else if ( 'cpt-child' == wpse121567_get_cpt_hierarchy() ) {
// Globalize post object
global $post;
// Output Parent CPT title and content
$parent = get_post( $post->post_parent );
echo '<h1>' . $parent->post_title . '</h1>';
echo '<div>' . apply_filters( 'the_content', $parent->post_content ) . '</div>';
// Fetch parent CPT comments
$parent_cpt_comments = get_comments( array(
'post_id' => $post->post_parent,
'status' => 'approve'
) );
// Loop through parent CPT comments
foreach ( $parent_cpt_comments as $comment ) {
// Output comment list markup here
}
}
// Grandchild CPT
else if ( 'cpt-grandchild' == wpse121567_get_cpt_hierarchy() ) {
// Comment Stats code goes here
?>
<?php
$enable_rtl = of_get_option('enable_rtl', false);
if(!of_get_option('disable_pagination')){
if($enable_rtl){
$next_post = get_adjacent_post( false, '', true );
$prev_post = get_adjacent_post( false, '', false );
}else{
$next_post = get_adjacent_post( false, '', false );
$prev_post = get_adjacent_post( false, '', true );
}
?>
<?php
}
// show related posts by tag
if(!of_get_option('disable_related_posts')){
get_template_part( 'inc/related-posts' );
}
// If comments are open or we have at least one comment, load up the default comment template provided by Wordpress
if ( comments_open() )
comments_template( '', true );
}else{ // Well, if there are no posts to display and loop through, let's apologize to the reader (also your 404 error) ?>
<article class="post error">
<h1 class="404"><?php _e('Page not found', 'outbox'); ?></h1>
</article>
<?php } // OK, I think that takes care of both scenarios (having a post or not having a post to show) ?>