How to give css for posts in a wordpress theme - php

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

Related

How to modify WooCommerce search results?

I reckon the WooCommerce search is using a URL like http://localhost/myshoesssite/?s=noheelshoes&post_type=product
Thus, I need to edit the search result so that I could add a URL parameter at the end of each product URL, like http://localhost/myshoesssite/product/no-heel-shoes?get=specs where get=specs is the parameter. I only wish to add this parameter in my search results, NOT in my typical product URL.
I tried using search.php in my theme but seems like when I edit the file, the search results don't change. Below is my search.php
<?php
/**
* The template for displaying search results pages.
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
*
*/
get_header(); ?>
<div id="primary" class="site-content content-wrapper topofset">
<div id="main" class="container" >
<div class="content content_search" >
<?php
if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title text-light"><?php printf( esc_html__( 'Search Results for: %s', 'myticket' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
</header><!-- .page-header -->
<?php
/* Start the Loop */
while ( have_posts() ) : the_post(); ?>
<span class="search-post-title">Testing<?php the_title(); ?></span>
<span class="search-post-excerpt"><?php the_excerpt(); ?></span>
<span class="search-post-link"><?php the_permalink(); ?></span>
<?php
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
//get_template_part( 'template-parts/content', 'search' );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</div>
</div><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
How do I achieve this?
Firstly, make sure you have a copy of archive-product.php under wp-content/themes/yourtheme/woocommerce folder. You can copy that file from wp-content/plugins/woocommerce/templates
Inside archive-product.php, you got to differentiate your search results between those appearing from the search and those appearing in the shop page because both are sharing the same template. Use something like below..taken from WooCommerce search result template
if ( is_search() ) {
//put your search results markup here (you can copy some code from archive-product.php file and also from content-product.php to create a standard markup
} else {
// here goes the content that is already in that file (archive-product.php)
}
It is within the is_search() if statement that you edit the search results as you wish. You could create another copy of content-product.php (again, copying from woocommerce template to your theme's folder) and inside that is where you get to customize your search results. You could override the hooks such as "woocommerce_before_shop_loop_item" by placing your new functions in functions.php under your theme folder.
It's easy, add this code to functions.php file:
function after_setup_theme_7cloner_com() {
add_theme_support(
'html5',
array(
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
'navigation-widgets',
)
);
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'after_setup_theme_7cloner_com' );

Wordpress beginner - style.css doesn't affect page.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(); ?>

Feed title appearing twice in wordpress responsive theme cyberchimps

I am using responsive mobile theme by cyberchimps in wordpress 4.1. When I am trying to read from a feed and display the post on my site, the title is being displayed twice.
I tried changing feeds-rss.php and feeds-rss2.php from
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
to
<title><?php bloginfo_rss('name'); ?></title>
but the title is still appearing twice.
The url is Here
Any idea any body?
Thanks
#Rohil_PHPBeginner
My archive.php has this as content and I have no idea which line to edit:
*
* #package responsive_mobile
* #license license.txt
* #copyright 2014 CyberChimps Inc
* #since 0.0.1
*
* Please do not edit this file. This file is part of the responsive_mobile Framework and all modifications
* should be made in a child theme.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
get_header(); ?>
<div id="content-archive" class="content-area">
<main id="main" class="site-main" role="main" itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/Blog">
<?php if ( have_posts() ) : ?>
<?php get_template_part( 'template-parts/loop-header' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to override 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( 'template-parts/content', get_post_format() );
?>
<?php endwhile; ?>
<?php responsive_mobile_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
<?php get_sidebar(); ?>
</div><!-- #content-archive -->
<?php get_footer(); ?>
The help is appreciated.
Thanks
Any idea anyone?
Nobody yet?
I suppose title in header is changed.
duplicated title is displayed as
<h1>the text</h1> and below of it <h2>the text</h2>
remove one of the header
Thanks a lot everybody.
I added the following code
<style>
h2 {
display:none;
}
</style>
in header.php and the error cleared out.
Thank you all.

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.

including a template within another template in wordpress

I am developing a very simple wordpress project. One of the page will have thumbnails of my projects and some texts and when I will click on the thumbnails it will land me to the page corresponding to the project. I created a template where i am trying to include another template which will just hold the thumbnails. I want to be able to update the thumbnails and text from two different pages from the wordpress dashboard. This is what I have so far...the concept is kinda goofy...let me know if i explained it correctly
lets say this is the rendering template
<?php
/*
Template Name: projects
* This template displays project thumbnails and introductory copy as a rendering template
*/
$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
get_header();?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<? /*php comments_template( '', true ); */?>
<?php endwhile; // end of the loop. ?>
<?php get_template_part( 'projectThumb', 'true' ); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
and this is the thumbnail template.
<?php
/*
Template Name: projectThumb
* This template displays project thumbnails at the project page
*/
$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
get_header();?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

Categories