How to call Custom Field in Wordpress Template - wordpress

I want to call custom field in single.php template to complete a short code and thus show a menu.
I places the below code but it is not working
<?php echo do_shortcode("[custommenu menu=<?php echo get_post_meta($post->ID, ‘tabmenu’, true); ?>]?>")
Please help
Here's my template file
I saved this as single-default.php and calling it category wise from single.php file
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="content">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tab-menu"><?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>
</div>
<div class="entry-content">
<?php if(get_option('resizable_integrate_singletop_enable') == 'on') echo (get_option('resizable_integration_single_top')); ?>
<?php the_content(''); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themejunkie' ), 'after' => '</div>' ) ); ?>
<?php if(get_option('resizable_integrate_singlebottom_enable') == 'on') echo (get_option('resizable_integration_single_bottom')); ?>
<div class="clear"></div>
<?php printf(the_tags(__('<div class="entry-tags"><span>Tags:</span> ','themejunkie'),', ','</div>')); ?>
<?php edit_post_link('('.__('Edit', 'themejunkie').')', '<span class="entry-edit">', '</span>'); ?>
</div><!-- .entry-content -->
</div><!-- #post-<?php the_ID(); ?> -->
<div class="clear"></div>
<div class="entry-bottom">
<div class="clear"></div>
</div><!-- .entry-bottom -->
</div><!-- #content -->
<?php endwhile; else: ?>
<?php endif; ?>

You need to concatenate the inner echo in the shortcode
<?php echo do_shortcode("[custommenu menu='".get_post_meta($post->ID, ‘tabmenu’, true)."']"); ?>

Related

Woocommerce search.php

How can I add price to 'search.php' in Woocommerce?
Current code is:
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
This also has the sidebar at the bottom and not the side - so if anyone can advise how to have the sidebar on the LEFT that too would help.
<?php
get_header();
global $wp_query;
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?>
<hr width=“20%”>
<h3><b><a href="<?php echo get_permalink(); ?>"></b>
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail( 'shop_thumbnail' ) ?>
<br/>
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
<div class="h-readmore"> <I>Click to see full details</I></div>
</hr width=“20%”>
<?php } ?>
</ul>
<?php paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
update you search.php with above code the price can we call with this <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>

WordPress get_query_var() with offset?

I am currently using get_query_var() to displays all post in the index.php page, and I wonder if it's possible to skip the latest post ( I am already displaying it on the home page...) using any offset parameter ?
<div class="wrapper section-inner">
<div class="content full-width">
<?php if (have_posts()) : ?>
<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">
<h4><?php printf( __('Page %s of %s', 'hemingway'), $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; ?>
</div> <!-- /posts -->
<?php endif; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="post-nav archive-nav">
<?php echo get_next_posts_link( __('« Older<span> posts</span>', 'hemingway')); ?>
<?php echo get_previous_posts_link( __('Newer<span> posts</span> »', 'hemingway')); ?>
<div class="clear"></div>
</div> <!-- /post-nav archive-nav -->
<?php endif; ?>
</div> <!-- /content -->
</div> <!-- /wrapper -->
Thanks for your feedback and suggestions
One way is to skip the first index:
<?php
$i = 0;
while (have_posts()) : the_post();
if($i > 0):
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php
endif;
i++;
endwhile;
?>

Creating Links to Custom Post Type's on Wordpress Page

I'm trying to have two things on a Wordpress page: a list of Custom Posts as well as the content of the custom posts. I would like the titles of the Custom Posts to link to the section of the page with the posts' content.
For example:
Item One
Item Two
Item Three
ITEM ONE HEADING
Item One content...
ITEM TWO HEADING
Item two content...
ITEM THREE HEADING
Item three content...
So "Item One" would link to "ITEM ONE HEADING". Here's the code I'm using which shows the Custom Post List as well as the content, but the list items link out to the Custom Post's page.
<ul>
<?php
$query = new WP_Query( array( 'post_type' => array( 'drilling' ) ) );
while ( $query->have_posts() ) : $query->the_post();
echo '<li><a href="';
the_permalink();
echo '">';
the_title();
echo '</a></li>';
endwhile;
?>
</ul>
<?php wp_reset_query(); ?>
and
<?php query_posts( 'post_type=drilling'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<section class="service-middle">
<div class="container">
<div class="service-middle-content sixteen columns">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php echo get_the_title($ID); ?> </h2>
<?php the_content(); ?>
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /article -->
</div> <!--end service-middle-content-->
</div> <!--end container-->
</section> <!--end service-middle-->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
Thanks so much for any help!
-Dan
You want to use HTML Anchors
http://www.w3schools.com/html/html_links.asp
It is worth mentioning that you don't actually need to query the posts twice. You could you the WP get_posts function (https://codex.wordpress.org/Template_Tags/get_posts) to get the posts as an array and then loop through this array to generate a nav and your post contents.
Hope this helps!
<ul>
<?php
$query = new WP_Query( array( 'post_type' => array( 'drilling' ) ) );
while ( $query->have_posts() ) :
$query->the_post();
?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php wp_reset_query(); ?>
<?php query_posts( 'post_type=drilling'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<section class="service-middle">
<div class="container">
<div class="service-middle-content sixteen columns">
<!-- Anchor Tag -->
<a name="post-<?php the_ID(); ?>"></a>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php echo the_title(); ?> </h2>
<?php the_content(); ?>
<br class="clear">
<?php edit_post_link(); ?>
</article>
<!-- /article -->
</div> <!--end service-middle-content-->
</div> <!--end container-->
</section> <!--end service-middle-->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>

Wordpress Pagination

I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here

WordPress Pagination on Page

I have the following code on a WordPress page. It basically just grabs 3 posts and displays them as well as the page content itself up top. What I want to add is pagination so that a user can flick through all the posts, how do I get this working with custom loops like this?
<?PHP
get_header();
/* Template Name: News */
?>
<div style="padding: 0 20px;">
<div class="box clearfix side" style="margin:10px 0;">
<div style="float:left;width:628px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' <small>[', ']</small>'); ?></h2>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<hr />
</div>
<?php endwhile; endif; ?>
<hr />
<?php $blog_query = new WP_Query('posts_per_page=3'); while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php else: ?>
<h2>oooops!!!</h2>
<?php endif; ?>
</div>
</div>
</div>
<?PHP
get_footer();
?>
Are you sure you're not re-inventing the wheel a little here? Why not set the number of posts to display in the admin, then use WP's native paging for the blog?
Turns out you have to do something like this:
<?php $temp = $wp_query; $wp_query= null; ?>
<?php $wp_query = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged)); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php $wp_query = null; $wp_query = $temp; ?>

Resources