Wordpress beginner - style.css doesn't affect page.php - php

Im a beginner in wordpress and while i was learning how to make themes I had a problem.
I use this code in my functions.php to add the css:
function learning() {
wp_enqueue_style('style', get_stylesheet_uri());
}
It works well for my index.php so i designed my default page as how I want. I wanted to change the look of my pages which I created in the WordPress GUI, so I created page-(otherpage).php file in my theme folder and copied the code etc, and gave different classes to the elements in page-(otherpage).php. Finally I made some changes in my style.css for my new classes but it doesn't change anything.
What should i do?

Attach a css file via function.php add following code into functions.php.
(Recommaded don't use function.php because its theme specific)
<?php
function mypage_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/includes/mypage.css">'."\n";
}
add_action('wp_head', 'mypage_head');
?>
method use for add header into a template
<?php get_header(); ?>
Created Template Page here :
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Related

Use different page template if ative content In Sidebar

Im using the UnderScore theme and below is the main page.php template file. What im aiming for is if there is active widgets in the sidebar use template with sidebar but if no active widgets or content use template that has the main content as 960px with no sidebar. Im also using ACF (advance custom fields) is the sidebar so would need to check that aswell. Gratefull for any help. I thought maybe using "is_active_sidebar" but unsure how to implerment it properly as template parts are already being check.
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
Also below the sidebar.php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<?php the_field('sidebar_info'); ?>
</aside><!-- #secondary -->
Maybe I'm not fully understanding you question, but you can use a simple if-statement for that. See pseudo code below.
if ( active widgets in the sidebar ) {
// use this formatting
} else {
// use that formatting
}

How to give css for posts in a wordpress theme

I new to wordpress development , I have developed a custom wordpress theme but i am not able to give css to the posts.Posts are rendering in very normal way but i want to give some css , please suggest me how i can do this .
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php get_footer(); ?>
I have added images how posts are appearing and code of page.php of my wordpress theme. Seeking some help
Add a css directory inside the your theme directory let create a file name "poststyle.css" inside that css directory and then you can link the css file in header.php
<link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() ); ?>/css/poststyle.css" media="screen" title="post-style" charset="utf-8">
OR
<?php
wp_enqueue_style( 'post-styles' , get_template_directory_uri() . 'css/poststyle.css' );
?>
but before that u need to find out the class or id or div name so that you can give or define the styles to that corresponding div's or classes inside "poststyle.css"
Now just take this example
<?php
/**
* The template for displaying 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_Fifteen
* #since Twenty Fifteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<div class="title"><?php the_title( '<h1>', '</h1>' ); ?></div>
<div class="pic"> <?php echo get_the_post_thumbnail( get_the_ID() , 'thumbnail' , array('class' => 'img-thumbnail') ); ?></div>
<div class="content"> <?php the_content() ; ?></div>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Now you can give styles to class="site-content" or class="content-area" , class="title", class="content"
But Incase of your post show template what you have doing is that you are importing another template which is inside template-parts directory content.php file where all the post content showing codes are there
You have to follow the the wordpress coding standard to create theme and plugins. To add css and js just create two folder inside your theme named 'js' and 'css'. Then add this code inside the functions.php
if(!function_exists('theme_style')):
function theme_style(){
wp_enqueue_script('main-js', get_template_directory_uri().'/js/main.js',array(),false,true);
wp_enqueue_style( 'main-css', get_template_directory_uri(). '/css/main.css', array(),false,'all' );
}
add_action('wp_enqueue_scripts','theme_style');
endif;
You can change the file name main.js and main.css

Loading custom pages with get_template_part()

I came across this function the get_template_part by talk to other person about what easy why to load custom page on front-end page he told me the get_template_part and i think its awesome for reuse of code. But him use it to loaded all my custom pages on front-page but when I view the site some content loads and some does not load on the site here screenshot.
<?php
/**
* Template Name: Front-Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-photography'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
<?php endwhile; ?>
</main><!-- #main -->
</div><!-- #primary -->
The problem is most likely either in the template files themselves, you're missing the template files, or your file names don't match your function call. For example to show your About page this code
<?php get_template_part('templates/page-about'); ?>
Means you should have a directory in your theme folder named 'templates' and a file in that directory called page-about.php. If all your files are present and correctly named you need to look in the template files themselves and check the code there
Based on the additional info you've posted on Linkedin, about the site being a one-page website, your problem is most likely because you're using the wrong file to load the homepage.
To solve this, do the following in the theme's folder:
Create a file called "home.php"
Move the contents of "page-home.php" to "home.php"
Remove the while loop so that home.php will look like this:
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php get_template_part('templates/header'); ?>
<?php get_template_part('templates/page-about'); ?>
<?php get_template_part('templates/page-services'); ?>
<?php get_template_part('templates/page-photography'); ?>
<?php get_template_part('templates/page-portfolio'); ?>
<?php get_template_part('templates/page-contact'); ?>
<?php get_template_part('templates/footer'); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>

Wordpress Blank Page with header/sidebar/footer of my template

How can i create a page in a directory like public_html/test1 that has a single blank page with the header/sidebar/footer of my actual template.
I can only see the header, no sidebar , no content ( by content i mean "Hello." ).
I'm using twenty fourteen template.
This is the php code i am using:
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
require (dirname(dirname( __FILE__ )).'/wp-load.php');
get_header();
get_sidebar();
?>
Hello.
Note: if i delete the the_content(); get_footer(); , then the header ONLY appears but without format.
Any help deeply appreciated
The content isn't appearing because there's no loop inside your template. Please add this code inside your template and move your template file to the 'page-templates' folder inside the twentyfourteen theme.
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
endwhile;
?>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_sidebar();
get_footer();
p.s. you can remove the div's if you'd like to.

WordPress blog dates are displaying the current date for every post

My WordPress blog, which is running a custom theme, displays the date for each entry post as the same date: today. I display the last three posts on my main home page, but those dates are fine. However my main blog page shows the current date for every post.
I am able to FTP into my site, and have access to all the PHP files, the problem is I don't know which file this error might be in, whether it be index.php, page.php, single.php, I have no idea. If anyone can suggest where the problem might be, I can help by sharing that code.
Here is the index.php
<?php
get_header(); ?>
<div class="wrap blog">
<h1>Blog</h1>
<div class="blog-left">
<div id="main-content" class="main-content">
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'content' ); ?>
</div><!-- #main-content -->
</div>
<div class="blog-right">
<?php get_sidebar(); ?>
</div>
</div>
<?php
get_footer();
Have a look at template hierarchy chart to figure out which file is used to display those posts. It might be archive.php, front-page.php, home.php, index.php depending on the theme and setup. From there, you'll see the function or which file is loaded to display each post's content.
Considering the sample code, its probably in content.php or in case it's a special post format, in content-{format}.php
I'm almost sure that if the theme is using Template Tags, is using the_date function, when it should be using the_timefunction.
You can read the docs for the_date, in the description there's a note you should read.

Categories