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' );
Related
I'm trying to figure out how in the best way to accomplish what the image show.
I've been trying with modulus to do a if/else, but since the custom post is also a post there will be duplicates. I'm thinking about creating 2 custom queries, one with all the ordinary posts and one with the custom post, but that will make it slower and it doesn't seem like a good solution..
Here's the code of home.php in the wp-content\themes\theme\home.php
<?php
get_header(); ?>
<div id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<div id="posts" <?php hive_blog_class( 'archive__grid grid masonry' ); ?>>
<?php /* Start the Loop */
while ( have_posts() ) : the_post();
/* 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( 'content', get_post_format() );
endwhile; ?>
</div>
<?php hive_paging_nav();
else :
get_template_part( 'content', 'none' );
endif; ?>
</div><!-- #main -->
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
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
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.
I'm intending to have a few different custom post types but I want them to have different layouts to that of the normal posts.
Normal posts have two different appearances themselves, one for the index page and one for when you click through to the permalink page.
For custom posts I want to do the same thing (two different layouts, both different from normal posts) but for some reason my code doesn't seem to be making a difference.
I've so far used custom post template plugin as well as tried to code in a post-[postype].php file, but both seemed ineffective.
For my single.php here's what the code is -
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<!--- post wrapper home/post --->
<?php if ( is_home()) { echo '<div class="fullposthome">' ; }
else { echo '<div class="fullpost">' ; }
?>
<?php if( get_post_meta($post->ID, 'imgtest', true) ) { ?> <!--- made following div appear if said custom field presetn ---->
<div class="testbox"><img src="<?php the_field('imgtest'); ?>" alt="" width="100%" height="auto"/></div> <!--- div with custom field inside --->
<?php } ?>
<?php if ( is_home()) { echo '<div class="contenttextboxhome">' ; }
else { echo '<div class="contenttextbox">' ; }
?>
<?php get_template_part( 'content', 'single' ); ?>
</div>
<?php temptheme1_content_nav( 'nav-below' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() )
comments_template();
?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!--- post wrapper --->
</div><!-- #primary -->
For custom posts I've tried changing the line
for custom posts I tried as that is what I'm assuming the names are referencing [content/single.php]
- this is in underscore.me / _S framework mind you, I'm also going to try on Thematic framework but since _S is more bare bones it would be easier for me to build it how I want it.
So my question I guess is where am I going wrong with my coding or how do I use the Custom Post Template plug in properly?
If your custom post type is "products"
then
Archive file should be : archive-products.php
Taxonomy should be : taxonomy-product_category_slug.php
Single file should be : single-products.php
if you want different content template then
create file of like content-product.php
and in your single.php use get_template_part( 'content', 'product' );
For current situation if everything working fine then just create content file, customize it.