I am making a custom theme based on twentytwelve. I am facing a problem regarding woocommerce shop page. I have a page template that work fine. However, when I activate woocommerce plugin and show the shop base page (using my custom page template) it removes all my custom divs and other custom contents. I have followed woocommerce documentation, using both woocommerce.php and action hooks. But it did not produce any result. Here is my code for the page template.
<?php
/**
* Template Name: Front Page Template
*
* Description: A page template that provides a key component of WordPress as a CMS
* by meeting the need for a carefully crafted introductory page. The front page template
* in Twenty Twelve consists of a page content area for adding text, images, video --
* anything you’d like -- followed by front-page-only widgets in one or two columns.
*
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<div class="rotator">
<ul id="rotmenu">
<?php
$recentposts=get_pages('number=5');
// echo $recentposts;
$ii=0;
if ($recentposts) {
$ii=0;
//foreach($recentposts as $page) {
//setup_postdata($page);
for ($ii=1;$ii<=5;$ii=$ii+1){
//$ii=$ii+1;
$title='r_slideshow_0'.$ii.'_title';
$image='r_slideshow_0'.$ii.'_uploader';
$details='e_slideshow_0'.$ii.'_textarea';
$link='r_slideshow_0'.$ii.'_link';
// echo $page;
// echo $title;
//echo $image;
//echo $details;
//echo of_get_option($image, 'no entry');
?>
<li>
<?php echo of_get_option($title, 'no entry');/*echo $page->post_title;*/ ?>
<div style="display:none;">
<div class="info_image"><?php echo of_get_option($image, 'no entry');?></div>
<div class="info_heading"><?php echo of_get_option($title, 'no entry'); ?></div>
<div class="info_description">
<?php echo of_get_option($details, 'no entry'); ?>
Read Details >><br/>
</div>
</div>
</li>
<?php
//$ii=$ii+1;
}
}
?>
</ul>
<div id="rot1">
<img src="" width="100%" height="300" class="bg" alt=""/>
<div class="heading">
<h1></h1>
</div>
<div class="description">
<p></p>
</div>
</div>
</div>
<!--#rotator on front static page-->
<?php
if(of_get_option('boxchoice_radio', '0' )){
?>
<!--box content-->
<div class="section_front_page group_front_page">
<div class="col_front_page span_1_of_3">
<img src="<?php echo of_get_option('frontpage_boximage_01' ); ?>"style=" ">
<?php if(of_get_option('frontpage_textarea_01' ) && of_get_option('frontpage_textarea_01' )!='Default Text')
{
?>
<?php echo of_get_option('frontpage_textarea_01' ); ?>
<?php } ?>
<br/>
<?php if(of_get_option('frontpage_linkarea_01' ) && of_get_option('frontpage_linkarea_01' )!='Default')
{
?>
Read More >>
<?php } ?>
</div>
<div class="col_front_page span_1_of_3">
<img src="<?php echo of_get_option('frontpage_boximage_02' ); ?>" style="">
<?php if(of_get_option('frontpage_textarea_02' ) && of_get_option('frontpage_textarea_02' )!='Default Text')
{
?>
<p>
<?php echo of_get_option('frontpage_textarea_02' ); ?>
</p>
<?php } ?>
<br/>
<?php if(of_get_option('frontpage_linkarea_02' ) && of_get_option('frontpage_linkarea_02' )!='Default')
{
?>
Read More >>
<?php } ?>
</div>
<div class="col_front_page span_1_of_3">
<img src="<?php echo of_get_option('frontpage_boximage_03' ); ?>"style=" float:right; width:100%;" >
<br/>
<?php if(of_get_option('frontpage_textarea_03' ) && of_get_option('frontpage_textarea_03' )!='Default Text')
{
?>
<?php echo of_get_option('frontpage_textarea_03' ); ?>
<?php } ?>
<?php if(of_get_option('frontpage_linkarea_03' ) && of_get_option('frontpage_linkarea_03' )!='Default')
{
?>
Read More >>
<?php } ?>
</div>
</div>
<!--#end of box content-->
<?php
} //end of boxes
?>
<!--#end of box content-->
<!--default content on page-->
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-page-image">
<?php the_post_thumbnail(); ?>
</div><!-- .entry-page-image -->
<?php endif; ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'front' ); ?>
<?php get_footer(); ?>
I have used this in my functions.php file to make it woocommerce compatible,
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
echo '<div id="main">';
}
function my_theme_wrapper_end() {
echo '</div>';
}
However, it did not work. Only the product shows up spanning full width on the page and default sidebar lies at its bottom.
I need some help on this. Can you give me any ideas?
Best is that you use the "template overwrite" method:
Copy the woocommerce/templates/ folder inside your theme folder, to yourtheme/woocommerce/
Inside that folder, you can modify the html structure to your heart's content and it will be used instead of woocommerce standard html templates.
Once this is done, open up these two files:
/wp-content/themes/your-theme/woocommerce/shop/wrapper-start.php
/wp-content/themes/your-theme/woocommerce/shop/wrapper-end.php
and modify the html to match yours.
there are two method one is Using woo commerce_content() and other is Using hooks so please follow first method to merge woo commerce in to your theme that documentation for merge woo commerce in to theme if you do not follow it willbe harmful for your theme design .....
Related
I create a Custom Post Type with ACF field inside. Everything works great, but when I want to create my archive-cpt.php page, I can't get my ACF field to be seen on this page.
Here is my archive page code :
<?php get_header(); ?>
<main role="main">
<!-- section -->
<section>
<h1><?php _e( 'Archives', 'trad' ); ?></h1>
<div class="container">
<div class="row">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="col-lg-4 mx-auto">
<!-- article -->
<h2 class="titre-extranet-article">
<?php the_title(); ?>
</h2>
<li>
<?php // display a sub field value
get_sub_field('titre'); ?></li>
</div>
<!-- /post thumbnail -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'trad' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
</div>
</div>
<?php get_template_part('pagination'); ?>
</section>
<!-- /section -->
</main>
<?php get_footer(); ?>
The sub field 'titre' doesn't appear on my archive page.
Where I am wrong ?
Thank you.
get_sub_field() is for a repeater field. So you need to get the parent first e.g.
if( have_rows('parent_field') ):
while ( have_rows('parent_field') ) : the_row();
$titre = get_sub_field('titre');
// Do something...
endwhile;
endif;
You can get that field just with get_field() if it is a single text field.
Try with get_field()
<?php echo get_field('titre'); ?>
And one more thing you forgot to add echo before the get_sub_field(). So try with the echo.
<?php echo get_sub_field( 'titre' ); ?>
I need help with using Wordpress conditional. The below code is the actual code I'm having problems with.
The goal is to check if the page is "bb_press" and if it is, load another template called "archive-forum".
If it's not, then continue using current template.
I tried defining if is_bbpress in the beginning, but I'm not doing something right. Perhaps the ending is the problem..
Help appreciated
<?php
if ( is_bbpress() ) {
get_template_part('archive-forum') {
else {
<--- Continue with the current template code --->
}
<?php endif;?>
<?php get_footer(); ?>
After this, I'm getting a blank page with nothing loaded.
EDIT: This is the orignal template I'm trying to modify. Without your suggestions. Tried them, but I'm doing something wrong. What am I missing here? Am I placing the "if" in the wrong place? Thank you all for your help so far.
<?php
/**
* Directory archive page
*
**/
get_header(); //Header Portion
$tmpdata = get_option('templatic_settings');
global $posts,$htmlvar_name;
do_action('after_event_header');
/* Left content side bar for all pages */
global $htmlvar_name;
if(function_exists('tmpl_get_category_list_customfields')){
$htmlvar_name = tmpl_get_category_list_customfields(CUSTOM_POST_TYPE_EVENT);
}else{
global $htmlvar_name;
}
if (!is_active_sidebar( 'tmpl_listings_left_content') ){
$class="content-middle";
}else{
$class="";
}
/* Here we use for Show left content sidebar , it can be use for many other purpose too */
do_action('tmpl_all_pages_left_content');
?>
<div class="content-sidebar <?php echo $class; ?>">
<script type="text/javascript">
var category_map = '<?php echo $tmpdata['category_map'];?>';
<?php if($_COOKIE['display_view']=='event_map' && $tmpdata['category_map']=='yes'):?>
jQuery(function() {
jQuery('#listpagi').hide();
});
<?php endif;?>
</script>
<!--taxonomy sidebar -->
<!--end taxonomy sidebar -->
<div class="page-head">
<?php
/* back page link */
tmpl_back_link();
do_action('after_directory_header'); /*do action for display the breadcrumb in between header and container. */
do_action('directory_before_container_breadcrumb');
?>
</div>
<?php
if ( is_active_sidebar('listingcategory_listing_above_content') ) : ?>
<div class="filters">
<div id="sidebar-primary" class="sidebar">
<?php dynamic_sidebar('listingcategory_listing_above_content'); ?>
</div>
</div>
<?php endif; ?>
<div class="view_type_wrap">
<?php /*do action to display the breadcrumb inside the container. */
/* Archive page title */
do_action('directory_before_archive_title'); ?>
<h1 class="loop-title">
<?php echo ucfirst(apply_filters('tevolution_archive_page_title','Listing'));?>
</h1>
<?php
if($archive_description[CUSTOM_POST_TYPE_LISTING]['description'] !=''){
?>
<div class="archive-meta"><?php echo $archive_description[CUSTOM_POST_TYPE_LISTING]['description']; ?></div>
<?php
}
do_action('directory_after_archive_title');
do_action('directory_before_loop_archive');
?>
</div>
<div id="content" class="contentarea large-9 small-12 columns <?php directory_class();?>">
<!--Start loop archive page-->
<div id="loop_listing_taxonomy" class="search_result_listing <?php if($tmpdata['default_page_view']=="gridview"){echo 'grid';}else{echo 'list';}?>" <?php if( is_plugin_active('Tevolution-Directory/directory.php') && $tmpdata['default_page_view']=="mapview"){ echo 'style="display: none;"';}?>>
<?php if (have_posts()) :
while (have_posts()) : the_post();
do_action('directory_before_post_loop');?>
<div class="post <?php templ_post_class();?>" >
<?php
/* Hook to display before image */
do_action('tmpl_before_category_page_image');
/* Hook to Display Listing Image */
do_action('directory_category_page_image');
/* Hook to Display After Image */
do_action('tmpl_after_category_page_image');
/* Before Entry Div */
do_action('directory_before_post_entry');?>
<!-- Entry Start -->
<div class="entry">
<?php /* do action for before the post title.*/
do_action('directory_before_post_title'); ?>
<div class="listing-wrapper">
<!-- Entry title start -->
<div class="entry-title">
<?php do_action('templ_post_title'); /* do action for display the single post title */?>
</div>
<?php do_action('directory_after_post_title'); /* do action for after the post title.*/?>
<!-- Entry title end -->
<!-- Entry details start -->
<div class="entry-details">
<?php /* Hook to get Entry details - Like address,phone number or any static field */
do_action('listing_post_info'); ?>
</div>
<!-- Entry details end -->
</div>
<!--Start Post Content -->
<?php /* Hook for before post content . */
do_action('directory_before_post_content');
/* Hook to display post content . */
do_action('templ_taxonomy_content');
/* Hook for after the post content. */
do_action('directory_after_post_content');
?>
<!-- End Post Content -->
<?php
/* Hook for before listing categories */
do_action('directory_before_taxonomies');
/* Display listing categories */
do_action('templ_the_taxonomies');
/* Hook to display the listing comments, add to favorite and pinpoint */
do_action('directory_after_taxonomies');?>
</div>
<!-- Entry End -->
<?php do_action('directory_after_post_entry');?>
</div>
<?php do_action('directory_after_post_loop');
endwhile;
wp_reset_query();
else:?>
<p class='nodata_msg'><?php _e( 'Apologies, but no results were found for the requested archive.', 'templatic' ); ?></p>
<?php endif;
if($wp_query->max_num_pages !=1):?>
<div id="listpagi">
<div class="pagination pagination-position">
<?php if(function_exists('pagenavi_plugin')) { pagenavi_plugin(); } ?>
</div>
</div>
<?php endif;?>
</div>
<!--End loop archive page -->
</div>
</div>
<?php get_footer(); ?>
This is correct code for your condition and will work fine. You have to close the brace for the condition. Check this for condition reference click here
<?php
if ( is_bbpress() ) {
get_template_part('archive-forum');
} else {
// continue with the current template code
}
get_footer();
?>
If you are using brackets, you do not need to use endif; This whole endif; and opening <?php and closing ?> in every row is very ugly. <!-- not valid in PHP code. And you need to add ; after get_template_part('archive-forum');
<?php
if ( is_bbpress() ) {
get_template_part('archive-forum');
} else {
//Continue with the current template code
}
get_footer();
?>
<!-- More none php code here. If there are no more php code, you can leave ?> -->
I want to display name of multiple authors on the front end like below
By John Doe,Linn Doe and Penny
In the back end I can add many users for the same post.But In the front end only the first author on the post shows up both for the byline and the bio. I'm using Twenty Thirteen theme and how to show all the user added in the back end in the front end?
this is my single.php file
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php twentythirteen_post_nav(); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Incorporate Co-Authors Plus template tags into your theme
Other Solution:
In order to add add Co-Authors Plus support you must have access to edit the theme template. In order to display information about multiple authors on the fronted, you'll need to add the necessary Co-Authors Plus template tags to your single.php and other theme files.
Specifically for the bylines, you'll want to replace where it says something like:
<?php the_author(); ?>
With something like this:
<?php if ( function_exists( 'coauthors' ) ) { coauthors(); } else { the_author(); } ?>
That specific snippet will allow your theme to degrade gracefully when Co-Authors Plus isn't activated.
To show the authors with their posts link, you'll want to use something like:
<?php if ( function_exists( 'coauthors_posts_links' ) ) { coauthors_posts_links(); } else { the_author_posts_link(); } ?>
You can use the following code for the bios
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ): ?>
<center><div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $coauthor->user_firstname; ?>.jpg" alt="" class="alignleft"/>
<?php $userdata = get_userdata( $coauthor->ID ); ?>
<?php if ( $userdata->user_description ) echo $userdata->user_description; ?>
</div></center>
<?php endforeach; ?>
Reference
I have developed a theme with custom post types. One of those post_types is called events.
I wan't to display the latest event in a "page" called "upcoming event". So i created this template file called "Events". Now i need to modify the global wp_query so that i return this last event.
This is how my single.php looks like:
<?php
get_header();
setup_postdata($post);
get_page_post_content();
get_footer();
?>
Works fine when viewing event as custom posts types "normal". And this is my template file which should contain the latest event:
<?php
/*
* Template Name: Event
*/
?>
<?php
global $wp_query;
$wp_query = new WP_Query('post_type=event&posts_per_page=1');
include 'single.php';
?>
However this does not work as expected since i have other parts of my template depending on properies like "is_single()" which is this case returns false, since the query is called from a page. I somehow need to set the query so those properies are changed. Anyone knows how or how i should solve this?
Thanks!! :D
Put below code in your template file.
<?php
/**
Template Name: Event
*/
get_header();
?>
<div id="content" >
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts('post_type=event&paged='.$paged.'&posts_per_page=10');
if (have_posts ()) :
while (have_posts ()) : the_post(); ?>
<div <?php post_class() ?>>
<div class="post-title">
<h2 class="alignleft"><?php the_title(); ?></h2>
</div><!-- .post-title -->
<div class="post-content">
<?php the_excerpt('read more');?>
</div>
</div><!--end of .post_class -->
<div class="post-meta">
<p class="alignright"><a class="readmore" title="<?php get_the_title();?>" href="<?php echo get_permalink( $post->ID );?>" rel="nofollow">Read</a></p>
<span class="alignright comment-cnt"><?php comments_popup_link( 'No Comments', '1 Comment', '% Comments' ); ?></span>
<div class="clear"></div>
</div><!-- end of .post-meta -->
<?php
endwhile;
endif;
?>
</div>
<div class="clear"></div>
</div>
<?php get_footer(); ?>
When I installed WordPress I had a home menu. While editing, I added a menu item to the menu but my home menu item disappeared.
I don't know what's going on. How do I add the home menu item which links to homepage back?
I'm not sure why your home item would have disappeared after adding another item, but make sure your theme is using wp_page_menu():
http://codex.wordpress.org/Template_Tags/wp_page_menu
This carries the benefit of listing your "Home" along with your other pages.
Edit the line in the header.php
wp_page_menu( 'show_home=1');
reference in the codex : http://codex.wordpress.org/Function_Reference/wp_page_menu
If you have already added Home as menu, then copy the content of index.php into your Home.php (create this empty file in your theme) file.
Then run and check the home page.
Step 1. For linking your home page, create index.php as template file for home like the code below:
Use these codes if you're using custom theme(theme created by yourself in themes folder of wp-content other than twentyelevan, twentyten and so on.
<?php
/**
* Template Name: home
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
// whatever body code u need,u can include it here.
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-header">
<!-- <div class="date"><?php the_time( 'M j y' ); ?></div>-->
<!-- <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent
Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>-->
<!-- <div class="author"><?php the_author(); ?></div>-->
</div><!--end post header-->
<div class="entry clear">
<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
<?php the_content(); ?>
<!-- <?php edit_post_link(); ?>-->
<?php wp_link_pages(); ?>
</div><!--end entry-->
<div class="post-footer">
<!-- <div class="comments"><?php comments_popup_link( 'Leave a Comment', '1
Comment', '% Comments' ); ?></div>-->
</div><!--end post footer-->
</div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
<div class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</div><!--end navigation-->
<?php else : ?>
<?php endif; ?>
<div id="slider">
<?php
$tmp = $wp_query;
$wp_query = new WP_Query('posts_per_page=5&category_name=featured');
if(have_posts()) :
while(have_posts()) :
the_post();
?>
<a href="<?php the_permalink(); ?>"><?php
the_post_thumbnail('nivothumb'); ?></a>
<?php
endwhile;
endif;
$wp_query = $tmp;
?>
</div><!-- close #slider -->
<?php get_footer(); ?>
Or, if you're using wordpress builtin themes, then use these codes:
<?php
/**
* Template Name: onebyone
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<html>
// whatever body code u need,u can include it here.
</html>
Step 2. Then open the home page in wordpress, Pages -> All pages, click edit.
Step 3. In edit page of home, in the right side you will see Dropdown named Template. Click the
dropdown, there you will see your template name as home select it and then click update
button.
Step 4. Then,On top left side corner,click your website or blog name and visit the website or
blog to check your home page by clicking on it.
Do you have a link to your site?
It may be as simple as checking a box. OR, you can create a custom menu.