I want to have two widgets on my home page next to each other. However I want the first widget to be 650 px, while the other to be 290px. This I am not being able to do.Can someone please help me?
The code I registered for my widgets in my theme functions.php file:
register_sidebar(array(
'name' => 'Slider 1',
'before_widget' => '<div id="%1$s" class="widget-area1 %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'Side Column',
'before_widget' => '<div id="%1$s" class="widget-area2 %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
Then I placed in my home page template file:
<?php
/**
* Template Name: Home Page
*/
get_header();
include('_functions/get-options.php');
?>
<?php /* Widgetised Area */ if(!function_exists('dynamic_sidebar') ||!dynamic_sidebar('Homepage')); ?>
**<div class="widget-area1">
<?php /* Widgetised Area */ if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Slider 1')); ?>
</div>
<?php /* Widgetised Area */ if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Side Column')); ?>**
<?php /* Widgetised Area */ if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage 1')); ?>
<?php /* Widgetised Area */ if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage 2')); ?>
<div class="clear"></div>
<?php get_footer(); ?>
And the css styling I placed in the stylesheet:
div.widget-area1 {
clear: both;
margin: 0 auto;
width: 650px;
}
div.widget-area3 {
clear: both;
margin: 0 auto;
width: 290px;
}
Can you please tell me what I am doing wrong?The theme that I am using is Compare if that might help.
The styles in your question like like they should work, but this is what I see in your stylesheet
#widget-area1 {
clear: both;
margin: 0 auto;
width: 650px;
}
#widget-area2 {
clear: both;
margin: 0 auto;
width: 290px;
}
These rules are in reference to an ID not to a class like you have defined in your question.
Also, you may want to remove the clear:both if you want them to sit side-by-side.
Related
I created a header widget. I used this code:
First, I placed this code into Functions.php
function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Header Widget',
'id' => 'header-widget',
'before_widget' => '<div class="hw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="hw-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpb_widgets_init' );
Then I added this code into header.php
<?php
if ( is_active_sidebar( 'header-widget' ) ) : ?>
<div id="header-widget-area" class="hw-widget widget-area" role="complementary">
<?php dynamic_sidebar( 'header-widget' ); ?>
</div>
<?php endif; ?>
Now my width of the widget seems to be smaller than my container width. I'd like to change that.
I tried using this code:
.header-widget {
clear: both;
margin: 0 auto;
width: 1200px;
}
But it does not seem to do anything. What am I doing wrong?
There is no class named header-widget in front end. header-widget is an ID of widget in backend. If you want to write CSS for your widget in front end then you can use header-widget-area or hw-widget widget-area as below. I tried and it worked for me in localhost.
#header-widget-area {
clear: both;
margin: 0 auto;
width: 1200px;
}
or
.header-widget {
clear: both;
margin: 0 auto;
width: 1200px;
}
I use a code that displays products under each category on the archive page /shop:
Category 1
product 1 product 2 product 3
Category 2
product 1 product 2 product 3
Here is my code:
<?php
foreach( get_terms( array( 'taxonomy' => 'product_cat' ) ) as $category ) :
$products_loop = new WP_Query( array(
'post_type' => 'product',
'showposts' => -1,
'tax_query' => array_merge( array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'terms' => array( $category->term_id ),
'field' => 'term_id'
)
), WC()->query->get_tax_query() ),
'meta_query' => array_merge( array(
// You can optionally add extra meta queries here
), WC()->query->get_meta_query() )
) );
?>
<h2 class="category-title"><?php echo $category->name; ?></h2>
<?php
while ( $products_loop->have_posts() ) {
$products_loop->the_post();
/**
* woocommerce_shop_loop hook.
*
* #hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata(); ?>
<?php endforeach; ?>
I also use a standard widget to display WooCommerce categories. As I understand it, the file is responsible for it - woocommerce / includes / widget / class-wc-widget-product-categories.php.
How can I modify this file (code for functions.php) to add anchor links? For example, in the categories menu, I select Category 2 and the page moves down to Category 2 with its products.
I just can’t find a ready-made solution, so I ask you for help. I hope this code will be useful to other users.
You need to add some javascript and add "data-link" attribute with a href for category term in your code
<h2 class="category-title" data-link="<?php echo get_term_link( (int) $category->term_id, 'product_cat' ); ?>"><?php echo $category->name; ?></h2>
I created a snippet to demonstrate:
$('.product-categories .cat-item > a').on('click', function(e) {
e.preventDefault();
var href = $(this).attr('href');
$('html, body').animate({
scrollTop: $("[data-link='" + href + "']").offset().top
}, 1000);
});
.left {
float: left;
width: 50%;
}
.right {
float: right;
width: 50%;
}
.category-wrapper {
height: 400px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="left">
<ul class="product-categories">
<li class="cat-item">
Category 1
</li>
<li class="cat-item">
Category 2
</li>
</ul>
</div>
<div class="right">
<div class="category-wrapper">
<h2 class="category-title" data-link="http://category1">Category 1</h2>
</div>
<div class="category-wrapper">
<h2 class="category-title" data-link="http://category2">Category 2</h2>
</div>
</div>
I'm building a custom WP Theme and am working on adding to The Customizer. I previously added a background image setting, and am trying to also implement an opacity slider. I looked up how to use the :before or :after pseudoclass to make opacity apply correctly to my background-image, but the children are still affected by the opacity setting. Is there something wrong with my code? I went off this site's example on how to format my html and css: https://scotch.io/quick-tips/how-to-change-a-css-background-images-opacity
HTML:
<div id="bg-image-div" class="image-opacity">
<section id="category-section">
<div class="container">
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<h2 class="section-title">Section Title</h2>
</div>
</div>
<div>
<p>
Content Content Content Content Content Content Content Content Content Content Content
</p>
</div>
</div> <!-- /.container -->
</section>
</div> <!-- /.image-opacity -->
CSS:
#bg-image-div {
position: relative;
overflow: hidden;
background: #5C97FF;
}
#bg-image-div:after {
content: ' ';
display: block;
position: absolute;
left: 0;
top: 0;
z-index: 1;
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 0;
-ms-background-size: cover;
-o-background-size: cover;
-moz-background-size: cover;
-webkit-background-size: cover;
background-size: cover;
}
#category-section {
z-index: 2;
position: relative;
}
PHP adding the Control and Settings:
function themename_customizer_register( $wp_customize ) {
// Theme Customizer -- Background Image CSS
$wp_customize->add_section(
'themename_recipe_category_area',
array(
'title' => __( 'Category Area Image', 'themename' ),
'priority' => 30,
'capability' => 'edit_theme_options',
'description' => __( 'Change the background image in the Recipe Category Area of the Home Page', 'themename' ),
)
);
$wp_customize->add_setting(
'themename_background_image',
array(
'default' => get_template_directory_uri() . '/images/rustic-bg.jpg',
'transport' => 'refresh'
)
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'themename_background_image',
array(
'label' => __( 'Background Image', 'themename' ),
'settings' => 'themename_background_image',
'section' => 'themename_recipe_category_area',
'description' => __( 'Recommended image size is approximately 1650x1650 pixels', 'themename' ),
)
)
);
// Theme Customizer -- Background Image CSS Opacity Slider
$wp_customize->add_setting('themename_image_opacity');
$wp_customize->add_control( 'themename_image_opacity',
array(
'type' => 'range',
'priority' => 20,
'section' => 'themename_recipe_category_area',
'label' => __( 'Set Background Image Opacity', 'themename' ),
'description' => '<span style="float: left; margin-top: 10px;">' . __( '← Less', 'themename' ) . '</span><span style="float: right; margin-top: 10px;">' . __( 'More →', 'themename' ) . '</span>',
'input_attrs' => array(
'min' => .1,
'max' => 1,
'step' => .1,
'class' => 'image-opacity',
'style' => 'width: 100%; padding-top: 0; z-index: 0;',
),
)
);
}
add_action( 'customize_register', 'recipedia_customizer_register' );
PHP/CSS hooking the style into wp_head:
function themename_customizer_css() {
?>
<style>
/*== Style from The Customizer Colors Section - Categories Section Background Image ==*/
<?php if(get_theme_mod('themename_recipe_category_area')) : ?>
#bg-image-div {
background-image: url("<?php echo get_theme_mod( 'recipedia_recipe_category_area' ) ?>");
}
<?php else : ?>#bg-image-div {
background-image: url("<?php echo get_template_directory_uri() . '/images/rustic-bg.jpg'; ?>");
}
<?php endif;
?>
/*== Style from The Theme Customizer Background Image - Adjusting Opacity ==*/
.image-opacity {
opacity: <?php echo get_theme_mod('themename_image_opacity') ?>;
}
</style>
<?php
}
add_action( 'wp_head', 'recipedia_customizer_css' );
Your CSS output for image opacity in the wp_head action hook looks incorrect. It should be
.image-opacity:after { ... }
Although, to match your original style, it's better to just go with
#bg-image-div:after { ... }
for the opacity properties so that there's no confusion between usage of CSS ID or class selectors if you have to edit this later.
I've actually utilized this very technique -- from that same article source -- and it works perfectly.
The default formatting puts the date after the title, I want the date to be displayed first and then the title, I also want to be able to separate them a little bit and make them look nice and lined up with a left justification.
The code is set to display a list of all the subpages of page.
<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => 701,
'show_date' => '1',
) ); ?>
I could not find option to modify it from PHP. So, here is small CSS tweak so that you can get date in the front. Check this:
<style>
#page-list li{
float: left;
display: inline-block;
clear: both;
}
#page-list li a{
float: right;
margin-left: 10px;
}
</style>
<ul id="page-list">
<?php
wp_list_pages( array(
'title_li' => '',
'child_of' => 701,
'show_date' => '1',
) ); ?>
</ul><!-- #page-list -->
i'm trying to display my portfolio items in a gird, but can't quite figure it out. ideally, i'd like the thumbnails to display 3 or 4 across(with the rest forming a second and/or third line) and once the thumbnails are clicked on, i'd like it to go to my normal post page.
css-
/* Portfolio */
#content {
width: 603px;
}
#portfolio-item {
display: inline;
float: left;
margin: 0 0 0 60px;
width: 280px;
}
#portfolio-item h1 {
font-size: 16px;
margin: 20px 0 5px 0;
}
#portfolio-item img {
height: 50%;
width: 50%;
}
portfolio.php:
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header(); ?>
<div id="portfolio">
<?php
$loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 10));
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$custom = get_post_custom($post->ID);
$screenshot_url = $custom["screenshot_url"][0];
$website_url = $custom["website_url"][0];
?>
<div id="portfolio-item">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
functions.php:
<?php // sidebar functions
if(function_exists('register_sidebar'))
{
register_sidebar();
}
// portfolio functions
add_action('init', 'create_portfolio');
function create_portfolio() {
$portfolio_args = array(
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type('portfolio',$portfolio_args);
}
// custom input- portfolio backend
add_action("admin_init", "add_portfolio");
add_action('save_post', 'update_website_url');
function add_portfolio(){
add_meta_box("portfolio_details", "Portfolio Options", "portfolio_options", "portfolio", "normal", "low");
}
function portfolio_options(){
global $post;
$custom = get_post_custom($post->ID);
$website_url = $custom["website_url"][0];
}
function update_website_url(){
global $post;
update_post_meta($post->ID, "website_url", $_POST["website_url"]);
}
// detail columns- portfolio backend
add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
add_action("manage_posts_custom_column", "portfolio_columns_display");
function portfolio_edit_columns($portfolio_columns){
$portfolio_columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Project Title",
"description" => "Description",
);
return $portfolio_columns;
}
function portfolio_columns_display($portfolio_columns){
switch ($portfolio_columns)
{
case "description":
the_excerpt();
break;
}
}
// add thumbnail support
add_theme_support('post-thumbnails');
// disable autoformat with raw
function my_formatter($content) {
$new_content = '';
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);
?>
http://www.cssbakery.com/2010/07/image-grid-using-css-floats_6950.html
This should be what you're looking for.
You can hardcode it was well with PHP if you'd like using a table if you can't get that CSS working, but that's not good coding technically.