I'm trying to set up a commercial website using Wordpress and I'm experimenting with different themes. I like "application", but I would like to get rid of the sidebar in "pages" (as opposed to "posts"). So I figured I would edit the template. I believe that is the file "page.php." I'm just learning PHP so some of this is mysterious. My immediate question is how to get rid of the sidebar, but more important than that, I just want to ask some basic questions about the structure of this file.
Here is page.php in the themes/application directory:
<?php get_header(); ?>
<!--content-->
<div id="content">
<div id="left-col">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="post-head-page">
<?php if ( is_front_page() ) { ?>
<h1><?php the_title(); ?></h1>
<?php } else { ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
</div><!--post-heading end-->
<div class="post-entry">
<?php the_content(); ?>
<div class="clear"></div>
<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'application' ), 'after' => '' ) ); ?>
</div><!--post-entry end-->
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
</div> <!--left-col end-->
<?php get_sidebar(); ?>
</div> <!--content end-->
</div>
<!--wrapper end-->
<?php get_footer(); ?>
Basic questions:
Does this represent the structure of both Pages and Posts? I only care about Pages (I won't use posts in my website; it's a commercial website)
I'm told that when I create a custom template, I have to conform to the structure of the pages in my theme. What is the "structure" of this file? How can I tell what that is for my theme?
And if you can see a simple way to remove the sidebar let me know.
This file only represents the structure for pages. Not for posts. To see what templates are used for what content, see this documentation, including a nice diagram.
I believe they mean that you'll need to keep the same html/php structure as in this file. When creating custom page templates, duplicate this file and then start adjusting it to your needs.
Remove the line with get_sidebar() to remove the sidebar.
Hope that helps!
Related
I'm trying to move the post's featured image below the post title in the Marketify theme, however I can't seem to find this hidden in the code.
Can anybody please help me find the code for the post's featured image? How do I move this below the post title?
Firstly, create a Child Theme for your WordPress Theme.
Then look in '/wp-content/themes/[theme-name], where you should find a file entitled 'single.php'. Copy this into your child theme, taking care to ensure you replicate the same directory hierarchy. The 'single.php' is usually the name of your default Blog Post Template.
Open up the 'single.php' file, which you have saved within your child theme, with a programme such as Notepad++ (Notepad will also do but is not as easy on the eye).
You should see something like:
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1> //This is the title of your Blog Post.
<div class="entry">
<?php the_content(); ?> //This is the content of your Blog Post.
</div>
<?php endwhile; ?>
<?php endif; ?>
There will be a slight variation in the coding but what you are looking to do is highlight:
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
and then move this coding to beneath <h1><?php the_title(); ?></h1>. You will need to play around as to where exactly you will need it but I hope this helps get you started.
The reason I have suggested that you do this within a Child Theme is that when the Theme Developer rolls out an update, it will delete any modifications you have made within the parent files.
Good Luck!
Thanks for your comment. I assumed it would be similar to code you've written too, but the title and featured image are hidden in the "do_action( 'marketify_entry_before' );".
get_header(); ?>
<?php do_action( 'marketify_entry_before' ); ?>
<div class="container">
<div id="content" class="site-content row">
<div role="main" id="primary" class="col-xs-12 col-md-8 <?php echo ! is_active_sidebar( 'sidebar-1' ) ? 'col-md-offset-2' : '' ?>">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
None the less, for anyone else with the same problem; I figured out how to hide this section in css like so...
.single .header-outer.has-image .page-header {
display: none;
}
And then could use the standard Wordpress functions to make the title and featured image appear where I wanted.
Thanks :)
Tom
I'm creating a blog with wordpress, I'm using the DIVI theme and I need to change the appearance of the category pages of the blog...
what's the easiest way to do that?
I understood I should look for category.php in the editor and create a new php file, but I couldn't find anything...
You will find category.php in your theme folder and customize according to your requirement.
If category.php file is not exist in your theme then you can create a new file with category.php name and do customization it will automatically uses this file when you will display category posts.
You need to create category template like below :
<?php
/**
* A Simple Category Template
*/
get_header(); ?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php
// Check if there are any posts to display
if ( have_posts() ) : ?>
<header class="archive-header">
<?php
// Since this template will only be used for Design category
// we can add category title and description manually.
// or even add images or change the layout
?>
<h1 class="archive-title">Design Articles</h1>
<div class="archive-meta">
Articles and tutorials about design and the web.
</div>
</header>
<?php
// The Loop
while ( have_posts() ) : the_post();
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<div class="entry">
<?php the_excerpt(); ?>
<p class="postmetadata"><?php
comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments closed');
?></p>
</div>
<?php endwhile; // End Loop
else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
First off, if there actually exists a file named category.php in your theme folder, it would be unwise to follow #Lalji Nakum's advice regarding editing the file directly. That would mean that you potentially lose all your changes in a future theme update. Instead you should either create a template file containing the ID or the slug of the category you would like to change. If you are to change the way all categories are displayed, you should instead create a child theme - holding your own version of category.php.
If there is no category.php in your theme folder, that means the theme controls this view in either archive.php or index.php. There's a strict hierarchy that WordPress follows, looking for a way to display categories. You would then create the file and make whatever changes to how they are to be displayed. A problem here might be that you would have to make it from scratch. An alternative would be to fall back to the child theme solution, track down where in fact your theme is controlling the view (in any of the two previously mentioned files), duplicate the file into your new child theme and do your changes here.
It's now established that you have no category.php in your theme today. You then have to choices, primarily. This is the best one:
Create category.php within your theme folder.
Create the contents of the file from scratch. A good place to start would here:
<div id="container">
<div id="content" role="main">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
get_template_part( 'loop', 'category' );
?>
</div><!-- #content -->
</div><!-- #container -->
Make all your wanted changes to the template.
Finished!
Creating a child theme is fairly simple, and is explained here: https://codex.wordpress.org/Child_Themes
Also it sounds like you are looking to create the file from the editor. That's not built in functionality, but could be managed resorting to creative solutions like this: http://ronangelo.com/create-new-theme-file-in-wp-admin-without-ftp/ . The better alternative would be to use ftp/ssh, though.
Read more about how category templates, including the mentioned hierarchy, work here: https://codex.wordpress.org/Category_Templates
I have my front page set to a static page and am trying to build my custom template. How do I actually show the selected front page in front-page.php? I have googled and googled but can't seem to figure out how to do it.
The front-page.php actually loads like it should, but I can't seem to find documentation on exactly how to show the page that is assigned as the static home page. Any suggestions?
I have tried
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
but that didn't seem to work...
Your static page uses a page template (usually page.php for the default template)
You can create a new one for the homepage if you wish. see : Creating_Your_Own_Page_Templates copy page.php to homepage.php and change the template name
Example template (homepage.php) :
<?php
/*
Template Name: Homepage
*/
//the content of page.php and now you can do what you want.
?>
$id = 0; /* The id of your page */
$page = get_page($id);
echo apply_filters('the_content', $page->post_content);
If its a static page, I should not use a loop.
First, take a look to topic to show something only on home page. a related question is Wordpress Post Thumbnail Issue (Only 1 thumbnail on frontpage). Also, it can be useful how to create a static front page in wordpress.
I was missing something obvious. The loop I was using I had copied out of wordpress template. It actually called another template file. What I should have used was:
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'twentytwelve'), 'after' => '</div>')); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php endwhile;?>
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')); ?>
I've got a wordpress blog theme which shows the content of all posts on the index fine but when I click into one of the posts the content of the post is blank and I can't seem to figure out why. If I'm correct the single.php controls that page.
http://pastebin.com/afLVxMPb = My single.php
an example of what I mean would be http://www.ndesign-studio.com/demo/wordpress/blog/how-about-a-blog-post-with-longer-title but on this site the content of the blog post does show up but on mine it doesn't.
I think the problem is somewhere here...
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
</div><!-- .entry-content -->
You should add "the loop" somewhere in your single.php file and call setup_postdata($post) or the_post() so you can access the post data inside that loop.
Read more about the loop here: http://codex.wordpress.org/The_Loop
For example, your single.php file will look something like this (simplified):
........
<div id="content">
<?php if(have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
// etc.. all post info
............
<?php endforeach; ?>
Hope that helps! Good luck.