Program PHP Header to Float Logo when search field is present - php

I'm reconfiguring a header for a Wordpress Theme. I just want to do this simple function:
Float the Logo to the center of the header when a search field is not present.
There used to be widgets in place where the search field is when a visitor navigates to a products page. I'd like to instead remove the rule that was in place for the widgets and float the Logo center, unless there is a search box, then I'd like to keep the Logo at the left.
Here is the code:
<div id="logo" class="col-sm-3">
<?php
$logourl = SNSSIMEN_THEME_URI.'/assets/img/logo.png';
if ( snssimen_get_option('header_logo') && snssimen_get_option('header_logo','','url') !='' ){
$logourl = snssimen_get_option('header_logo','','url');
}
?>
<a href="<?php echo esc_url( home_url('/') ) ?>" title="<?php echo esc_attr(get_bloginfo( 'sitename' )); ?>">
<img src="<?php echo esc_url($logourl); ?>" alt="<?php echo esc_attr(get_bloginfo( 'sitename' )); ?>"/>
</a>
</div>
<div class="header-right col-sm-9">
<div class="header-right-inner">
<div class="row">
**<?php if ( $snssimen_topHeaderSidebar == 'header_sidebar'):?>
<?php if(is_active_sidebar('header_sidebar')) dynamic_sidebar('header_sidebar');?>**
<?php else: // Header sidebar search box?>
<div class="col-md-8">
<div id="headerRightSearchForm">
<?php // Get Woocommerce categoies
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 0,
'title_li' => '',
'hide_empty' => 0
);
$all_categories = get_categories($args);
?>
The coding in the asteriks is the coding for what was there, but is not there anymore. Any suggestions? Regards.

Related

Wordpress - Category image

I know this question was asked so many times, but none of the solutions are working for me.
I want to display my categories on the website with their thumbnails together.
I tried to use category imagies plugin, but for some reason this plugin stopped working and doesn't give me the opportunity to attach picture to the category (the add image button isn't shown in the category settings).
After this I created custom field, where I made a taxonomy is equal to category. With this I could pair images with categories, but I don't know how to add it to the code.
Here is my code:
<section id="categories">
<div class="center-box">
<div class="categories">
<?php
$categories = get_categories(array ('parent' => 0));
foreach($categories as $category) { ?>
<div class="category-box">
<a class="category-img" href="<?php echo get_category_link($category->term_id); ?>">
<img class="img" src="<?php echo z_taxonomy_image_url($category->term_id); ?>"/>
<div class="category-name">
<h3> <?php echo $category->name; ?> </h3>
</div>
</a>
</div>
<?php
$args = array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'category' => $category->term_id, );
?>
<?php } ?>
</div>
</div>
</section>
It still has the previous category imagies plugin code which doesn't work anymore.
Someone could help me how to display the categories with image?
Thank you!
I'd suggest using the Advanced Custom Fields plugin for this, if you are not already. Under the working assumption that you are, you could do the following:
<section id="categories">
<div class="center-box">
<div class="categories">
<?php
$categories = get_categories(array ('parent' => 0));
foreach($categories as $category) { ?>
<div class="category-box">
<a class="category-img" href="<?php echo get_category_link($category->term_id); ?>">
<img class="img" src="<?php echo wp_get_attachment_image_src( get_field( 'thumbnail', "term_$category->term_id" ), 'small' ) ?>"/>
<div class="category-name">
<h3> <?php echo $category->name; ?> </h3>
</div>
</a>
</div>
<?php
$args = array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'category' => $category->term_id, );
?>
<?php } ?>
</div>
</div>

single-product.php not opening

I have created a set of pages. In first page product.php all the custom categories are shown (title and image). If a user clicks on it then it moves to the taxonomy-product_categories page where products are shown of the specific category. Now i want that if user clicks on the product then it goes to single-product.php page.
code is here
<?php
get_header();
$slug = get_queried_object()->slug; // get clicked category slug
$name = get_queried_object()->name; // get clicked category name
$tax_post_args = array(
'post_type' => 'products', // your post type
'posts_per_page' => 999,
'orderby' => 'id',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_categories', // your taxonomy
'field' => 'slug',
'terms' => $slug
)
)
);
?>
<div id="main-wrap">
<div class="container">
<?php
$counter = 1;
$tax_post_qry = new WP_Query($tax_post_args);
if ($tax_post_qry->have_posts()) {
while ($tax_post_qry->have_posts()) {
$tax_post_qry->the_post();
$the_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $type);
//var_dump($the_url);
if ($counter % 4 == 0) {
echo '<div class="row product-gallery">';
}
?>
<div class="col-sm-3">
<div class="product-warp">
<div class="product">
<img src="<?php echo $the_url[0] ?>" title="" alt="">
</div>
<div class="product-name">
<h5>
<a href="">
<?php echo get_the_title();
; ?>
</a>
</h5>
</div>
</div>
</div>
<?php
if ($counter % 4 == 0) {
echo '</div>';
}
?>
<?php
}
}
?>
</div>
</div>
<?php get_footer(); ?>
this is the place where user clicks then it should go to single-product.php
<a href="#"><img src="<?php echo $the_url[0] ?>" title=""
Somebody guide me step by step please
If your post_type => products Then your file name must be like this single-products.php
Read this article
And for precautions (if the page not open yet. means give 404 error) go to
admin panel
settings
permalinks
First save permalinks as plain and refresh your site home page.
Then save permalinks as post_name and again refresh your home page
Hope this will help you.
Please Try
'post_type' => 'products'
Your Post type is “products”.
And wordpress ruls is “single-{post_type}.php”.
You make “single-products.php” and remove “single-product.php”
https://codex.wordpress.org/Post_Type_Templates

get_queried_object()->image ; cannot get image

I have created a custom taxonomy for products. In custom taxonomy user can enter name and can upload a image. In the products page I can get the image and title of category. When user clicks on this it moves to next page where description of post and title is shown.
I also want to get image also in this next page.
Here is the code: For showing custom categories
foreach($terms as $term) {
$prod_meta = get_option("taxonomy_term_".$term->term_id);
if(($counter % 4) == 0) {
echo '<div class="row product-gallery">';
}
?>
<div class="col-sm-3">
<div class="product-warp">
<div class="product">
<img src="<?php echo $prod_meta['img']; ?>" title="" alt="">
</div>
<div class="product-name">
<h5>
<a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
<?php echo $term->name; ?>
</a>
</h5>
</div>
</div>
</div>
For product detail page
<?php
get_header();
$slug = get_queried_object()->slug; // get clicked category slug
$name = get_queried_object()->name; // get clicked category name
$tax_post_args = array(
'post_type' => 'products', // your post type
'posts_per_page' => 999,
'orderby' => 'id',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_categories', // your taxonomy
'field' => 'slug',
'terms' => $slug
)
)
);
$tax_post_qry = new WP_Query($tax_post_args);
if ($tax_post_qry->have_posts())
while($tax_post_qry->have_posts()) :
$tax_post_qry->the_post(); ?>
<div class="row product-details">
<div class="col-sm-7">
<div class="fire-product">
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>

WordPress: Not able to get current ID.

I'm very new to WordPress, and I've been pulling hair trying to figure this one out.
I have a custom theme, the theme is very simple, which contains an image carousel built up from a collection of images in a gallery.
If I remove the carousel include file, the post ID on the rest of the page returns correctly, as soon as I add the carousel back, it uses the ID of the last category pulled in the code.
I removed all 'global' references, as I assumed this will override the ID for the rest of the page, but it's still wrong.
The code from the carousel.php file:
<div id="carousel">
<?php
$args = array(
'post_type' => 'gallery',
'post_status' => 'publish',
'name' => $wp_query->query_vars['name'],
'posts_per_page' => 1
);
$second_query = new WP_Query($args);
$gllr_options = get_option('gllr_options');
$gllr_download_link_title = addslashes(__('Download high resolution image', 'gallery'));
if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post(); ?>
<div class="carousel-holder">
<?php
the_content();
$galleries = get_posts(array(
'showposts' => -1,
'what_to_show' => 'posts',
'post_status' => 'inherit',
'post_type' => 'attachment',
'orderby' => $gllr_options['order_by'],
'order' => $gllr_options['order'],
'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png',
'post_parent' => $post->ID
));
if (count($galleries) > 0) { ?>
<ul id="carousel-gallery">
<?php foreach ($galleries as $attachment) {
$key = 'gllr_image_text';
$link_key = 'gllr_link_url';
$alt_tag_key = 'gllr_image_alt_tag';
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'photo-thumb' );
$image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
$image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
if ( 1 == $gllr_options['border_images'] ) {
$gllr_border = 'border-width: ' . $gllr_options['border_images_width'] . 'px; border-color:' . $gllr_options['border_images_color'] . '';
$gllr_border_images = $gllr_options['border_images_width'] * 2;
} else {
$gllr_border = '';
$gllr_border_images = 0;
}
if (($url_for_link = get_post_meta($attachment->ID, $link_key, true)) != "") { ?>
<li>
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $url_for_link; ?>" />
</li>
<?php } else { ?>
<li rel="gallery_fancybox<?php if ( 0 == $gllr_options['single_lightbox_for_multiple_galleries'] ) echo '_' . $post->ID; ?>">
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $image_attributes_large[0]; ?>" />
</li>
<?php }
$count_image_block++;
} ?>
</ul>
<div class="clearfix"></div>
<div id="arrows" class="arrows">
<a id="prev" class="prev" href="#"></a>
<a id="next" class="next" href="#"></a>
</div>
<div id="paginator" class="paginator"></div>
<?php } ?>
</div>
<?php endwhile; else: endif;?>
</div>
The code that is returning the erroneous ID:
<div class="left sidebar">
<?php echo the_ID(); ?>
</div>
This is within a template page, that looks like this:
<?php
/**
* Template Name: 2 Column Left
*/
get_header();
?>
<div id="maincontent">
<div id="content" class="site-content" role="main">
<div class="left sidebar">
<?php
echo the_ID();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
Carousel.php is defined within header.php, and then gets called when get_header(); is called.
So, assuming I'm on the About page, with an ID of 16, and the carousel calls a gallery with page ID of 8, the echo in left-sidebar always returns 8.
I'm at a loss here, I've search high and low for an answer to this problem, but I've come up with nothing.
Try resetting the loop using the wp_reset_query() method.
Place this right after your carousel loop ends.
<?php wp_reset_query(); ?>

WordPress Gallery on single page

My current WordPress theme has a built in gallery. Each gallery displays the first / main thumbnail and once clicked opens the entire content of this specific gallery in a shadowbox. My ideal goal now is to find a way to alter this that instead of displaying the shadowbox directly it would direct to a single page with the specific galleries content.
As below my current gallery code:
<div id="maincontentwrap">
<div class="main-sep">
</div><!-- .main-sep -->
<div id="contentwrap">
<div id="content-gallery" role="main">
<?php
$wp_query = new WP_Query();
$wp_query->query( array( 'post_type' => 'galleries', 'posts_per_page' => of_get_option('le_gallery_items'), 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
$mod = 1;
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') );
if(has_post_thumbnail()) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$src = $src[0];
}
else{
foreach ( $attachments as $id => $attachment ) {
$src = wp_get_attachment_url( $id );
}
}
if ($mod % 3 == 0) {
echo ' <div class="gallery-entry-img-last">';
}
else{
echo ' <div class="gallery-entry-img">';
}
?>
<div class="gallery-entry-img-l"><a rel="next" href="<?php echo $src; ?>"><span class="rollover" ></span><img class="blog-entry-img" src="<?php echo get_bloginfo('stylesheet_directory'); ?>/library/tools/timthumb.php?src=<?php echo $src; ?>&w=270&h=198" alt="<?php get_the_title(); ?>"/></a>
<span class="gallery-entry-img-tab"></span>
</div>
<span class="gallery-index-title"><?php the_title(); ?></span>
<div class="hidden-gallery">
<?php
$pic_count = 0;
foreach ( $attachments as $id => $attachment ) {
$pic_count++;
$others_src = wp_get_attachment_url( $id );
?>
<a rel="next" href="<?php echo $others_src; ?>" title="<?php the_title(); ?>"></a>
<?php
}
?>
</div><!-- .hidden-gallery-->
</div>
<?php
$mod++;
endwhile;
?>
<div style="clear:both;"></div>
</div>
</div><!-- #contentwrap-->
</div><!-- #maincontentwrap-->
Would anybody have an idea how I can have this achieved? Some expert advise would be truly appreciated.
Use wp_get_attachment_link( $id, $size, $permalink, $icon, $text ); (see http://codex.wordpress.org/Function_Reference/wp_get_attachment_link). This outputs the link to the attachment page. So you just need to adapt your code with this function. Use value = 0 for the $permalink argument so your link brings you to the attachment page (value = 1 will bring you to the file itself).
Beware, though, that the "shadowbox" is probably triggered by event binding (clicking on the anchor) in a JavaScript, so you might have to adapt your HTML code for the links. If the selector in the script for shadowbox uses a class name or an ID to detect the click, you will probably need to change the ID or class name of the container of your link in order to be sure that your target page does not get displayed within the shadowbox.
You can also (and should, actually) use wp_deregister_script() to deregister the script that displays the shadowbox, considering you don't need it in this page.

Categories