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 ?> -->
Related
I edit a new page, here is the content.
Publish and view it.
Why is nothing displayed?
The theme is "twentyfourteen".
sudo cat /var/www/html/wp/wp-content/themes/twentyfourteen-child/page.php
<?php /* Template Name: Custom Front Page */ ?>
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other ‘pages’ on your WordPress site will use a different template.
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
get_header(); ?>
<div id=”main-content” class=”main-content”>
<div id=”primary” class=”content-area”>
<div id=”content” class=”site-content” role=”main”>
<p>it is a test</p>
</div><!– #content –>
</div><!– #primary –>
<?php get_sidebar( ‘content’ ); ?>
</div><!– #main-content –>
<?php
Why are all the double quotation marks ” instead of ", and single quotation marks are ‘ instead of '?
How do I get my page to display?
Are the quotation marks in the right format?
You don't print the content on the site. The best way do to this is to do it with the WordPress loop. So the code should look something like this:
<?php </* Template Name: Custom Front Page */ ?>
<?php get_header(); ?>
<div id="main-content" class="main-content">
<div id=”primary” class=”content-area”>
<div id="content" class="site-content" role="main">
<?php if(have_posts): while(have_posts): the_post(); ?>
<h1><?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
<?php get_sidebar( 'content' ); ?>
</div>
<?php get_footer(); ?>
No it should be " and '
i m new to Drupal 7 and in this forum, please be nice :)
I m trying to customize a bit the drupal module "On the web" (that display facebook and youtube link button). This module work great but I would like to to modify the position of the social images provided by this module inside a sub theme of Zen. I could be nice to put it at the left-top the header region.
As it says in the documentation I :
1)
Place the following code in the template.php file in your theme, and replace 'mytheme' with the name of your theme:
/**
* Overrides theme_on_the_web_image().
*/
function mytheme_on_the_web_image($variables) {
return $variables['service'];
}
2) I add this line : <div id="myidtomodifythecssafter"> <?php print $service; ?></div> in the page.tpl.php like following :
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan">
<div id="myidtomodifythecssafter"> <?php print $service; ?></div>
<?php if ($site_name): ?>
<?php if ($title): ?>
<div id="site-name"><strong>
<span><?php print $site_name; ?></span>
</strong></div>
<?php else: /* Use h1 when the content title is empty */ ?>
<h1 id="site-name">
<span><?php print $site_name; ?></span>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php if ($site_slogan): ?>
<div id="site-slogan"><?php print $site_slogan; ?></div>
<?php endif; ?>
</div><!-- /#name-and-slogan -->
<?php endif; ?>
3) I cleared the cache
but then the module images don't appear and i got this error in the front page :
Notice: Undefined variable: service in include()
i don't understand, what did I miss ?
Ok after reading the module code :
The function zhongdao_on_the_web_image is for theming the rendering of your anchor tags. Not really what you want here, so you can remove it.
This module create a block (under admin > structure > bloc) that you can position anywhere in your theme regions, then up to you to style it differently with CSS.
But if you want to render the block content another solution is this one :
https://www.drupal.org/node/26502
Wich will translate to something like this :
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan">
<div id="myidtomodifythecssafter">
<?php
$block = module_invoke('on_the_web', 'block_view', 0 /* might want to change depending of your block*/);
print render($block['content']);
?>
</div>
<?php if ($site_name): ?>
<?php if ($title): ?>
<div id="site-name"><strong>
<span><?php print $site_name; ?></span>
</strong></div>
<?php else: /* Use h1 when the content title is empty */ ?>
<h1 id="site-name">
<span><?php print $site_name; ?></span>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php if ($site_slogan): ?>
<div id="site-slogan"><?php print $site_slogan; ?></div>
<?php endif; ?>
</div><!-- /#name-and-slogan -->
<?php endif; ?>
I'm building my own template for Wordpress and I'm bumping into an issue when displaying the content of a post.
I have already built one page template for the home page and it works fine. The loop outputs what I want to display. Now I'm building the template to display an article but the loop doesn't return anything.
Here is the code of the page template:
<?php
/*
Template Name: PAGE
*/
define( 'WP_USE_THEMES', false );
get_header();
?>
<div class="wrapper">
<div class="sidebar">
<?PHP get_sidebar(); ?>
</div>
<div class="main">
<div class="section group">
<div class="col col12-12">
<span>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</span>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
This results in displaying the "sorry, no posts matched your criteria" message when i click on one of the links on the homepage. The strange thing is that the page really exists (it has ID=26 as you'll see here below):
<?php
$post = get_post(26);
$title = $post->post_title;
echo $title;
?>
This works and displays the expected title. I have tried get_the_ID(); to get the post ID but it returns an empty variable.
There is probably something missing in my template but I can't figure out what.
Any idea?
Thanks
I have found the issue and it had nothing to do with the template itself.
I discovered what's wrong by using one of the standard Wordpress themes (twentyfifteen) where every post led me to a 404 even if I clicked on a post from the Admin UI. I swapped back permalink structure to the ?p=123 option and there everything working. Definitely a permalink structure problem.
The problem was coming from the polylang plug-in. I'm using a network of wordpress site for which I have made this plug-in available. I did not need this plug-in for this particular site but somehow it needed to be active anyway. So I activated polylang and configured it to have only one language and now it works.
Got new gray hair in the process but if that can help anyone...
Thanks for your help!
Laurent
I don't think, that this template can output any posts like this. For WordPress
/*
Template Name: PAGE
*/
indicates: this is a page-template which you can asign to the content of a page but not to a post.
When you want to show a specific post on such a page you will have to:
Asign the template to the page in WP-backend
Add a new query to the template to show the post
Like:
<?php
/*
Template Name: PAGE
*/
define( 'WP_USE_THEMES', false );
get_header();
?>
// The new Query
$args = array (
'p' => '26',
);
// The Query
$query = new WP_Query( $args );
<div class="wrapper">
<div class="sidebar">
<?PHP get_sidebar(); ?>
</div>
<div class="main">
<div class="section group">
<div class="col col12-12">
<span>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</span>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
But as this is very complicated I would recommend to:
delete the /* Template Name: PAGE */ from the template
save it as single.php or more specific as single-26.php
link to the desired post in your wp-menu
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 .....
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(); ?>