I'm trying to use bootstrap tabs in my index.php theme to show diferent content in the main page theme.
I've implemented the tabs in index.php and create new page called popular-post.php linked in the tab Popular.
But when I click in the link to show popular content I get
Fatal error: Call to undefined function get_header() in
This is the code of my index.php
<?php get_header(); ?>
<div class="row" id="content">
<div class="col-sm-8 col-md-8 col-lg-8" id="primary">
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li>Popular</li>
<li>Recientes</li>
</ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile;?>
<?php /* Pagnavi plugin support */ wp_pagenavi(); ?>
<?php else: ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</div>
<div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
<?php get_sidebar(); ?>
</div>
</div><!--/content-->
<?php get_footer(); ?>
An this is the code of popular-post.php
<?php
/*
Template Name: Popular Posts
*/
?>
<?php get_header(); ?>
<div class="row" id="content">
<div class="col-sm-8 col-md-8 col-lg-8" id="primary">
<ul class="nav nav-tabs">
<li>Home</li>
<li class="active">Popular</li>
<li>Recientes</li>
</ul>
<ul class="popular_posts">
<?php $pc = new WP_Query('orderby=comment_count&posts_per_page=10');
while ($pc->have_posts()) : $pc->the_post(); ?>
<li><?php the_title(); ?>
<p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
<?php endwhile; ?>
</ul>
</div>
<div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
<?php get_sidebar(); ?>
</div>
</div><!--/content-->
<?php get_footer(); ?>
Thanks in advance
You can't link to a theme file directly like: Popular.
This is an invalid URL: http://example.com/wp-content/themes/YOUR-THEME/any-theme-file.php.
Create a new page, "Popular Posts", select the template (your file already has a Page Template header. Take note of the page ID (in the URL). And link like:
Popular
This produces a valid URL: http://example.com/popular-posts/, which is a piece of your content (a page), that uses the defined page template file.
To get the page ID by its title use get_page_by_title:
$the_page = get_page_by_title('popular-posts');
echo 'Popular';
Reading about the Template Hierarchy will also help.
Related
I am using a Wordpress template made with Cherry Framework. The complete footer only appears on the home page. I would like it to appear on all page types, which are mostly 'fullwidth page templates'.
When I look at the PHP files for each template, the difference I can see is this:
<?php do_action( 'cherry_after_home_page_content' ); ?>
I can't seem to find where cherry_after_home_page_content is defined. Could this be what I'm looking for? I tried copying that into the fullwidth page template, but it doesn't work. If I'm totally off base, what would be the correct way to accomplish this?
Footer that appears on every page regardless of template type. Here is the screenshot:
Code from fullwidth page template:
<?php
/**
* Template Name: Fullwidth Page
*/
get_header(); ?>
<div class="motopress-wrapper content-holder clearfix">
<div class="container">
<div class="row">
<div class="<?php echo cherry_get_layout_class( 'full_width_content' ); ?>" data-motopress-wrapper-file="page-fullwidth.php" data-motopress-wrapper-type="content">
<div class="row">
<div class="<?php echo cherry_get_layout_class( 'full_width_content' ); ?>" data-motopress-type="static" data-motopress-static-file="static/static-title.php">
<?php get_template_part("static/static-title"); ?>
</div>
</div>
<div id="content" class="row">
<div class="<?php echo cherry_get_layout_class( 'full_width_content' ); ?>" data-motopress-type="loop" data-motopress-loop-file="loop/loop-page.php">
<?php get_template_part("loop/loop-page"); ?>
</div>
</div>
</div>
<?php do_action( 'cherry_after_home_page_content' ); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
Complete footer that only appears on the home page. Below is a screenshot:
Code from homepage template:
<?php
/**
* Template Name: Home Page
*/
get_header(); ?>
<div class="motopress-wrapper content-holder clearfix">
<div class="container">
<div class="row">
<?php do_action( 'cherry_before_home_page_content' ); ?>
<div class="<?php echo apply_filters( 'cherry_home_layout', 'span12' ); ?>" data-motopress-wrapper-file="page-home.php" data-motopress-wrapper-type="content">
<div class="row">
<div class="<?php echo apply_filters( 'cherry_home_layout', 'span12' ); ?>" data-motopress-type="static" data-motopress-static-file="static/static-slider.php">
<?php get_template_part("static/static-slider"); ?>
</div>
</div>
<div class="row">
<div class="<?php echo apply_filters( 'cherry_home_layout', 'span12' ); ?>" data-motopress-type="loop" data-motopress-loop-file="loop/loop-page.php">
<?php get_template_part("loop/loop-page"); ?>
</div>
</div>
</div>
<?php do_action( 'cherry_after_home_page_content' ); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
I figured this out, so just for anyone who comes across this with the same problem.
The "cherry_after_home_page_content" had nothing to do with it. (And actually I noticed afterward that in my pasted code above I accidentally put in the code where I had pasted it in to the fullwidth page template where it does not belong. Ooops!)
Anyway, it is just in the CSS. If you are seeing that the footer widgets only appear on your homepage, you probably have this in your CSS:
.home .footer .footer-widgets { display:block; }
In your child theme, paste in the above code but change .home to the pages where you want it to show up. For me it was .page for all regular pages, .blog and .single-post for the blog.
Hope that helps someone!
For classipress theme. I can register post_formats the normal way in functions (works - I can select "link" type in the editor), but I can't figure out how to get it to actually use a template file for link posts.
I have used the get_template_part('content', get_post_format()); in the past successfully,
but I can't figure how to inject that into the single.php's code for this theme:
Single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
Content.php
<?php
/**
* Post loop content template.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 3.4
*/
?>
<div <?php post_class( 'shadowblock_out' ); ?> id="post-<?php the_ID(); ?>">
<div class="shadowblock">
<?php appthemes_before_blog_post_title(); ?>
<h3 class="loop"><?php the_title(); ?></h3>
<?php appthemes_after_blog_post_title(); ?>
<?php appthemes_before_blog_post_content(); ?>
<div class="entry-content">
<?php if ( has_post_thumbnail() ) the_post_thumbnail( 'blog-thumbnail' ); ?>
<?php the_content( __( 'Continue reading ...', APP_TD ) ); ?>
</div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- #shadowblock -->
</div><!-- #shadowblock_out -->
Tried a lot of things, unsuccessful in doing anything but breaking the page.
Thanks
Post formats are used to customize the presentation of post items. If you check out some theme that supports post formats (For example Twenty Fifteen), you will see that the single.php file is not used to output the contents of the post - which is delegated to content-*.php files. (For example, the the_content() function, which outputs a post's content is not in single.php, but in content.php (and content-link.php and others).
Your single.php does not seem to be built this way, so it does not support post formats, but it can be refactored easily, just split it into two files (in single.php you should keep the "frame" code that is common for every post format, then move the rest into a new content.php file, which will be used as the default format):
single.php
<?php
/**
* The Template for displaying all single posts.
*
* #package ClassiPress\Templates
* #author AppThemes
* #since ClassiPress 1.0
*/
?>
<div class="content">
<div class="content_botbg">
<div class="content_res">
<div id="breadcrumb"><?php cp_breadcrumb(); ?></div>
<div class="content_left">
<?php appthemes_before_blog_loop(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php appthemes_before_blog_post(); ?>
<?php appthemes_stats_update( $post->ID ); //records the page hit ?>
<?php
// Note the below line which loads the desired content*.php
get_template_part('content', get_post_format());
?>
<?php appthemes_after_blog_post(); ?>
<?php endwhile; ?>
<?php appthemes_after_blog_endwhile(); ?>
<?php else: ?>
<?php appthemes_blog_loop_else(); ?>
<?php endif; ?>
<div class="clr"></div>
<?php appthemes_after_blog_loop(); ?>
<div class="clr"></div>
<?php comments_template(); ?>
</div><!-- .content_left -->
<?php get_sidebar( 'blog' ); ?>
<div class="clr"></div>
</div><!-- .content_res -->
</div><!-- .content_botbg -->
</div><!-- .content -->
content.php
<div class="shadowblock_out">
<div class="shadowblock">
<div class="post">
<?php appthemes_before_blog_post_title(); ?>
<h1 class="single blog"><?php the_title(); ?></h1>
<?php appthemes_after_blog_post_title(); ?>
<div style="margin-top:10px; text-align:center;">
<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
</div>
<?php appthemes_before_blog_post_content(); ?>
<?php if ( has_post_thumbnail() ): ?>
<div id="main-pic">
<?php cp_get_blog_image_url(); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<div class="dotted"></div>
<div class="pad5"></div>
<?php appthemes_after_blog_post_content(); ?>
</div><!-- .post -->
</div><!-- .shadowblock -->
</div><!-- .shadowblock_out -->
Now, for additional post formats, for example gallery, you will have to create a file named content-gallery.php and implement it. You can derive it from the default content.php, but you decide how it should look like.
I'm extending an already existing plugin called Anspress. I'm new to wordpress/web dev and I can't figure out how the author makes different pages show up without creating different page templates. These images show how there is only 1 page template in the dashboard using a single shortcode. Within this "page" created by the plugin, there are links to load other sections of the plugin, such as user profiles, individual questions and their responses, and the main question list.
In a nutshell, his code layout is as follows:
main.php
{
require_once 'FileA.php'
require_once 'FileB.php'
require_once 'FileC.php'
require_once 'FileD.php'
/// Etc...
}
None of the files above are ask.php, which is the PHP file used to hold the HTML for the ask-question page. Yet he can still make this ask.php file somehow generate the page when a user clicks on the "Ask a question" button. How does this work? Below is the code for ask.php
<?php
// Some comment about the HTML code below
?>
<div id="ap-ask-page" class="clearfix">
<?php if (ap_user_can_ask()): ?>
<div id="answer-form-c">
<div class="ap-avatar ap-pull-left">
<a href="<?php echo ap_user_link(get_current_user_id()); ?>"<?php ap_hover_card_attributes(get_current_user_id()); ?>>
<?php echo get_avatar(get_current_user_id(), ap_opt('avatar_size_qquestion')); ?>
</a>
</div>
<div class="ap-a-cells clearfix">
<div class="ap-form-head">
<?php _e('Toggle fullscreen', 'ap'); ?>
<ul class="ap-form-head-tab ap-ul-inline clearfix ap-tab-nav">
<li class="active"><?php _e('Write', 'ap'); ?></li>
<?php if(ap_opt('question_help_page') != '') : ?>
<li><?php _e('How to ask', 'ap'); ?></li>
<?php endif; ?>
</ul>
</div>
<div class="ap-tab-container">
<div id="ap-form-main" class="active ap-tab-item">
<?php ap_ask_form(); ?>
</div>
<div id="ap-form-help" class="ap-tab-item">
<?php if(ap_opt('question_help_page') != ''): ?>
<?php ap_how_to_ask(); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php elseif (is_user_logged_in()): ?>
<div class="ap-no-permission">
<?php _e('You don\'t have permission to ask question.', 'ap'); ?>
</div>
<?php endif; ?>
<?php ap_get_template_part('login-signup'); ?>
</div>
I can provide more info as needed.
I have different categories where the post displayed are characterized by different elements, for this reason when I use the search in wordpress the results are not shown very well.
For this reason I would like to change the appearance of the post shown in the search results based on its category.
Example:
My search.php template look like this:
<?php get_header(); ?>
<div id="content">
<div class="padder">
<?php do_action( 'bp_before_blog_search' ); ?>
<div class="page" id="blog-search" role="main">
<?php if (have_posts()) : ?>
<?php bp_dtheme_content_nav( 'nav-above' ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php do_action( 'bp_before_blog_post' ); ?>
<div class="blog-post">
// Here is displayed the blog post style and features
</div><!--blog-post-->
<div class="clear"> </div>
<?php do_action( 'bp_after_blog_post' ); ?>
<?php endwhile; ?>
<?php bp_dtheme_content_nav( 'nav-below' ); ?>
<?php else : ?>
<h2 class="center"><?php _e( 'No posts found. Try a different search?', 'OneCommunity' ); ?></h2>
<?php endif; ?>
<div style="display:inline">
<center><?php wp_pagenavi(); ?></center>
</div>
</div>
<?php do_action( 'bp_after_blog_search' ); ?>
</div><!-- .padder -->
</div><!-- #content -->
<div id="sidebar">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-blog')) : ?><?php endif; ?>
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-ad-blog')) : ?><?php endif; ?>
</div><!--sidebar ends-->
<?php get_footer(); ?>
I tried to achieve the result of displaying based on the post category a different "template" for the post but without success.
I asked the same question on wordpress.stackexchange.com but without success, and there I pointed out a non working solution, hope it can help you in developing the code I need.
https://wordpress.stackexchange.com/questions/141856/different-layout-on-search-page-depending-on-category-post
Thank you very much for any help you will give, and excuse me for my english.
If I understand your question correctly, you could simply use the post_class() function:
<div <?php post_class( 'blog-post' );?> >
// Here is displayed the blog post style and features
</div><!--blog-post-->
This will render like:
<div class="post-3654 post type-post status-publish format-standard hentry category-buildings blog-post">
// Here is displayed the blog post style and features
</div><!--blog-post-->
for posts in the buildings category.
Then your CSS will take care of the rest:
.post.category-buildings {
border: 3px solid red;
}
But I think your setup/idea is only suitable for single category posts.
Ref: From the Codex:
The post_class may include one or more of the following values for the
class attribute, dependent upon the pageview.
.post-id
.post
.attachment
.sticky
.hentry (hAtom microformat pages)
.category-ID
.category-name
.tag-name
.format-name
I am needing some serious Wordpress expertise from others. I am in the process of building a custom theme, read about the get_template_part() method and decided that would help in cleaning up and organizing my code. I updated my theme to use this method several places and now the site is completely broken...not a single thing will load!! :( I would really appreciate any help! I will copy and paste a few of the php files below. Maybe someone with more experience with using this method can point out the problem. THANKS!
page.php
<?php get_header(); ?>
<div id="content" class="content">
<?php while ( have_posts() ) : the_post(); ?>
<!-- About page -->
<?php if (is_page('about')) ?>
<?php get_template_part( 'page', 'about' ); ?>
<!-- Media & Gallery page -->
<?php if (is_page('media-gallery')) ?>
<?php get_template_part( 'page', 'mediagallery' ); ?>
<?php endwhile; // end of the loop. ?>
</div> <!--/end content -->
<?php get_footer(); ?>
page-about.php
<div id="about">
<div class="text">
<h2 class="about"><?php echo get_the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
page-mediagallery.php
<div id="pic-gallery">
<?php include_once 'includes/pwaplusphp/albums.php'; ?>
</div>
index.php
<?php get_header(); ?>
<div class="content">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<br class="clr"/>
<?php endwhile; ?>
<?php content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h3 class="blog"><?php _e( 'Nothing Found' ); ?></h3>
</header> <!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.'); ?></p>
</div> <!-- .entry-content -->
</article> <!-- #post-0 -->
<?php endif; ?>
</div> <!--/end content -->
<?php get_footer(); ?>
content-gallery.php
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-date"><?php the_time(get_option('date_format')); ?></div>
<h3 class="blog"><?php the_title(); ?></h3>
<div class="post-content"><?php the_content(); ?></div>
</div>
Any thoughts why these may not be working? All of these files are under the root directory of the theme so the get_template_part() method should be finding all of the files. What's weird is no code is being spit out by Wordpress. aka. Since I've started using this method, not a single line of code is spit out in my browser when I inspect the source.
I am using the newest version of Wordpress and Google Chrome for my browser.
I also have this code at the top of each of my .php files, but that shouldn't mess up anything because it's commented as seen below:
<?php
/**
* I put a description of what the file does here.
*
* #package Keynote_WP_Themes
* #subpackage Rhymz_Suhreal
* #copyright Rhymz Suhreal, 2012
* #author Kyle Affolder <myemail#example.com>
*/
?>
I don't have the slightest clue as to what I'm doing wrong. :(
Ideas coding friends?!
Using your page-about.php as an example, you should be calling it like this in the template it's to be place in:
<?php get_template_part( "page-about" ); ?>
The template needs to be in the root of your theme directory so you can use "page-about" without the .php, and not have to indicate the location/directory the file would otherwise be located.
I've run into this a few times before as well - I can't really explain why yet as I'm still digging through the documentation, but it seems you can't call template parts this way when you are inside a post loop ;)
Anytime you are inside the loop, try using this instead:
<?php include(get_query_template('page-about')); ?>