There seems to be a problem with something on my wordpress page as a widget isn't displaying but I'm not sure how to edit the widget.
The code on homepage.php under Appearance>Editor is
<section class="row post_content">
<div class="col-sm-8">
<?php the_content(); ?>
</div>
<?php get_sidebar('sidebar2'); // sidebar 2 ?>
</section> <!-- end article header -->
Where would I find the code for 'sidebar2' as at the moment an error message appears on the page where the sidebar should display
As outlined in the Developer handbook for get_sidebar(), your sidebar file should be called sidebar-sidebar2.php. This file will be present in the root directory of your active theme.
The get_sidebar() hook allows a specific sidebar template file to be used in place of the default sidebar template file. If your file is called sidebar-new.php, you would specify the filename in the hook as get_sidebar( 'new' ).
Related
I am developing a custom theme in WordPress, and am trying to put custom HTML and PHP in my home page template. Whenever I am posting code for divs or custom fields in my home page template, they are simply not rendering and displaying on the front end. In the example below, the <div class="col-full"> is not being shown on the front end.
<?php
/*
Template Name: home
*/
?>
<!DOCTYPE html>
<?php get_header(); ?>
<center>
<div class="col-full">
<?php get_template_part( 'content', get_post_format() ); ?>
</center>
<?php get_footer(); ?>
Looking at your code, you've set it up as a template file. These need to be manually selected from the page as the template for it to work.
I'd recommend consulting the wordpress template hierarchy https://wphierarchy.com/. This shows you which files will try to be loaded based on what page you're visiting.
If you're still having trouble, i'd suggest installing the plugin https://en-au.wordpress.org/plugins/query-monitor/, which will tell you the template being loaded as well as other handy information.
I'm new to wordpress and i'm trying to create a custom template. I'm using the default twentyfifteen theme. I went to wp-content/themes/twentyfifteen and copied page.php to a new file called page_with-contact.php and added this comment on the top :
/*
Template Name: Page with contact
*/
I made no other changes to the template.
I then went to the admin site and changed one of the pages to "page with contact".
When I open the page I see that the affix on the left menu is not working and the responsive menu is not working either.
I followed a pretty simple tutorial here so I'm just wondering what am I doing wrong.
EDIT
Following #masiorama's answer and the comments below is crated a child theme, moved the template file to the child theme and renamed it to page-with-contact.php, This is the content of the template
<?php
/*
Template Name: Page with contact
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main my-content-page" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
?>
<div class="hentry entry-content contact-form">
<?php
echo do_shortcode('[contact-form-7 id="19" title="contact form 1"]');
?>
</div>
<?php
// End the loop.
endwhile;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php
get_sidebar();
get_footer();
?>
Now I have several problems :
As you can see the sidebar, heading and footer are all included but the affix and responsive menu are still not working.
The contact form (which previously worked fine) is now not showing at all.
I'm unable to enqueue the parent's rtl.css file.
Appreciate any further guidance.
As far as I know your page file should be named:
page-with-contact.php
and not:
page_with-contact.php
Be sure that it contains at least some wordpress function calls like:
<?php get_header(); ?>
<!-- stuff -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Check this for more details: http://codex.wordpress.org/Page_Templates
Looks like you are calling a template within a template. 'get_template_part( 'content', 'page' );' should be the_content();. Good chance that's whats messing you around.
Need this WordPress hooke to call in your template
get_header();
get_sidebar();
get_footer();
I'm using the YARPP plugin for a custom hosted wordpress site. I've changed the default location settings so that it only displays the widget where I specify (see screenshot). When I call the plugin in my single.php file it is moving the widget inside of the article.post, even when I try and contain it in a separate wrapping div.
single.php:
<article class='post'>...</article>
<div class='yarpp-wrapper'>
<?php if (function_exists('related_posts') ) : related_posts(); endif; ?>
</div>
output:
<article class='post'>...</article>
<div class='yarpp-related'>...</div> <!-- yarpp plugin-->
<div class='yarpp-wrapper></div> <!-- empty wrapper -->
I believe it's because you are using a custom yarpp template. Select 'List' instead, leave the other options above unchecked, and make sure the php script is in your single.php file. No need to wrap it in anything. Just place wherever you want it to show.
<?php related_posts(); ?>
Ok I just developed my first custom Wordpress theme using a guide - I'm still a noob. I'm not using widgets to fill the sidebar, I want to fill it myself with my own code and images.
So lets say I want the first sidebar I made to show up only on the homepage, and then the 2nd sidebar I made to show up on every other page. Can I use an if statement?
<?php
if(is_home()){
echo
"<div class="row">
<div class="span3">
<div id="search-box"><img id="search_text" src="http://localhost/Dorsa/wp-content/themes/Bootstrap/img/text_findyourhome.png">
</div>
</div>
</div>
<div class="row">
<div class="span3">
<img class="box_shadow" src="http://localhost/Dorsa/wp-content/themes/Bootstrap/img/box-shadow.png" style="padding-left:0;">
</div>
</div>
<div class="row">
<div class="span3"><div id="news" style="margin-top:275px;margin-bottom:200px">News</div></div>
</div>"
}
else
{
echo
"sidebar 2 code - didn't write it yet"
}
?>
You can use if statement as said by #ChrisHerbert if you just want to display one sidebar in homepage and other in rest of your pages. New solution would be by creating a new template and sidebar.
First find your sidebar.php file and make a copy of it.
Name the sidebar using wordpress naming convention eg: sidebar-secondary.php.
Make changes in sidebar-secondary.php as per your need.
Make a new template and use your sidebar as <?php get_sidebar(‘secondary’); ?>
EDIT
Assuming that you want one sidebar for homepage and separate for all others you can do the following.
Create sidebar-secondary.php as mentioned above.
The main template is usually index.php. This will usually contain the sidebar for your homepage. You will find some code like <?php get_sidebar() ?>.
If you want secondary sidebar on say page, open your page template page.php. Find the line get_sidebar() and replace it with get_sidebar('secondary'). Now all of your page will use secondary sidebar. You need to do the same if any of your page is using different template.
To display secondary sidebar in you single post page (the page displayed after user clicks readmore in blog section), open single.php and again find and replace get_sidebar() with get_sidebar('secondary').
You can now style and use your sidebar differently for homepage and other pages.
Note that if you only want different sidebar in homepage and same for rest of the page you can also use conditional in your main template file index.php.
if( is_home() ){
get_sidebar(); //your main sidebar for homepage
} else {
get_sidebar('secondary'); //your sidebar for other pages
}
Templates are definitely the way to go, but your solution should work assuming that your "home" page is your blog page. If you've set the home page to be a static page (in the "Reading" section of the dashboard), you should use the is_front_page() function instead of is_home().
I'd also suggest using alternative syntax and closing the PHP tag before your markup, like this:
<?php if ( is_home() ) : ?>
<div class="row">
<div class="span3">
<div id="search-box"><img id="search_text" src="http://localhost/Dorsa/wp-content/themes/Bootstrap/img/text_findyourhome.png">
</div>
</div>
</div>
<div class="row">
<div class="span3">
<img class="box_shadow" src="http://localhost/Dorsa/wp-content/themes/Bootstrap/img/box-shadow.png" style="padding-left:0;">
</div>
</div>
<div class="row">
<div class="span3"><div id="news" style="margin-top:275px;margin-bottom:200px">News</div></div>
</div>
<?php else: ?>
<!-- sidebar 2 code - didn't write it yet" -->
<?php endif; ?>
I wish to add a custom page to wordpress, not in the usual sort of way. This page has my own custom script and functions and to develop a plugin is beyond my means so I was wondering if this is possible:
Suppose I were to build it on the existing page.php script in my there folder, my script looks something like this:
<?php get_header(); ?>
<div id="left-area" class="clearfix">
<?php
//My script would go here
?>
<div class="comments">
<?php comments_template('',true); ?>
</div><!-- end of comments div -->
</div><!-- end of left-area -->
<!-- LEFT AREA ENDS HERE -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Is this even possible? I tried and got a page not found error. And if so, how do I call this script assuming WP is installed in the root directory? Example: www.mysite.com/myscript
Absolutely. Duplicate page.php. Rename it to template_mine.php. Open to edit, and before the get_header tag, add:
<?php
//
// Template Name: My Custom template (choose something more descriptive, like contact page)
//
?>
Go to Wordpress dashboard for pages, create a new page with your title, and in the Page attributes on the right hand side, under templates, select your template name, update, and you are all set.
Reference: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates