Genesis Framework Hooks - php

Is there any possible way to change the loop structure of the Genesis Framework so that the loop header appears within the same div as the entry content?
I have tried messing around with the loop.php file in the genesis template and I have also tried looking up different hooks, but I can't seem to find anything that helps.
Is there anyone that has accomplished this or would have an idea?

To customize the loop in Genesis, before you need to remove Genesis Loop:
remove_action( 'genesis_loop', 'genesis_do_loop' );
then you can add your custom loop
add_action( 'genesis_loop', 'my_custom_loop' );
Here is a basic example for 'standard-looking' loop working in Genesis:
function my_custom_loop() {
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
// Your Code Here
<?php endwhile; ?>
<?php endif; ?>
<?php
}
genesis();
?>
Please note that your function must end with 'genesis();' to work!
So the whole page code can be:
<?php
/*
* Your Custom Page
*/
?>
<?php
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'my_custom_loop');
function my_custom_loop() {
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
// Your Code
<?php endwhile; ?>
<?php endif; ?>
<?php
}
genesis();
?>
Hope it helps ;)

Here is simple approach.
You first remove the entry header stuff from the header.
e.g.
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
Once the header markup as well as entry title and entry info is removed from top.
You can add them back into your page in your desired position i.e. genesis_entry_content hook.
e.g.
add_action( 'genesis_entry_content', 'genesis_do_post_title' );
Hope this helps. Let me know if you face any issue.
Sorry forgot to add that you will need to add this custom code in your child theme's functions.php file if you want it to impact to whole site. And if you want this to happen on certain template, then in that template file in the child theme of Genesis.

I list all the most common Genesis hooks and filters used by me while developing a website without boring you with more contents.
https://icodefy.com/common-genesis-hooks-filters/

Related

woocommerce remove all tabs, display their content on page

After trying every function I could find and 2+ days of trying every snippet possible for functions.php I have been unable to find a working solution for this.
I am trying to remove the WooCommerce description and review tab, and just display the description in place of the tabs, and have the contents of the reviews tab beneath it... with no tabs to click. - I an unset the tabs and remove, but cannot add their contents back in.
I have tried "Remove single product tabs and add the related content instead In Woocommerce" answer code.
I do not mind even overriding php in the theme, but nothing seems to work... the goal is just to have the description show, and the reviews beneath with no tabs. Any help is appreciated.
To remove the tabs but display the content you can use the following.
// Remove
function remove_product_tabs( $tabs ) {
unset( $tabs['description'] );
unset( $tabs['reviews'] );
unset( $tabs['additional_information'] );
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 98, 1 );
// Tabs callback function after single content.
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_description_tab' );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_additional_information_tab' );
add_action( 'woocommerce_after_single_product_summary', 'comments_template' );
To avoid collapsing, edit the following template
https://github.com/woocommerce/woocommerce/blob/master/templates/single-product/tabs/description.php
This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/description.php.
Replace
<?php if ( $heading ) : ?>
<h2><?php echo esc_html( $heading ); ?></h2>
<?php endif; ?>
<?php the_content(); ?>
With
<div style="clear:both;">
<?php if ( $heading ) : ?>
<h2><?php echo esc_html( $heading ); ?></h2>
<?php endif; ?>
<?php the_content(); ?>
</div>
Further customization is a matter of html and/or css modifications, depending on your theme

WordPress change search results

I have got the problem that my WordPress theme ("Sydney") is displaying the search results wrong. Instead of just listing posts I want to display WooCommerce products only.
Those should be ordered in a nice grid as shown in this picture:
.
At the moment the results are listed like this
.
How can I change the way the search results are displayed?
At the moment my search.php is looking like this:
<?php get_header(); ?>
<div id="primary" class="content-area col-md-9">
<main id="main" class="post-wrap" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h3><?php printf( __( 'Search Results for: %s', 'sydney' ), '<span>' . get_search_query() . '</span>' ); ?></h31>
</h3>
</header><!-- .page-header -->
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?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( 'content', 'search' );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
Thank you guys a lot!
** UPDATE
The solution provided by kashalo partly worked, but search results still look slightly different from the product page and are listed in only one column instead of a grid.
** UPDATE
The solution suggested by Alexander Wigmore looks almost the way I wanted it so look like. The only Problem with copying the page.phpin the search.phpis that the products are still getting displayed wheird, but not when they are displayed in the category they fit in. For example: When searching for saat the results are displaying the products at first with text only, but normaly under the Saatgut category.
my advise is not to directly modify the search file of wp or theme template but is a good practice to work with the child theme. For the design display of the result you can play a little with css to customize it as you want, instead for the results to show only the products you can use any filter builded on the theme you are using (if it have) or create yourself a function to filter the results (also called hooks).
An example for filtering results is like the above code:
add_action( 'pre_get_posts', 'filter_woocommerce_products' ); // the hook
function filter_woocommerce_products( $query ) { // the function
if( ! is_admin() && is_search() && $query->is_main_query() ) {
// verify if can use the search function and the search string is from the search call
$query->set( 'post_type', 'product' ); // filter the posts with type products that corrispond to woocommerce products.
}
}
and this function must be saved on the function.php file of your theme or the child theme.
For more information i suggest you to read more about child theme and the pre_get_posts documentation on the wp page.
Hope it helps and feel free to ask.
You'll want to modify the way search is handled by Wordpress.
This can easily be done by adding an "action", add the below code to your functions.php file.
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('product'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
This will then make the search page only show products. It's worth noting that you can add other post types back in via the array in this line: $query->set('post_type',array('product'));.

How to add a custom block as a usual "product" to shop page / archive-product.php

I'm looking for a possibility to add a custom html block/post to the woocommerce "shop page" inside the products grid, as a product.
What I mean.. I have a grid of products on the "shop" page (archive-product) and I want to create a special post/page/html block with some text information, that will be inserted into the products grid as a one of "product", but with no price, with no title and unclickable. I've attached the screenshot of the final result I want to have, it's really self explaining - here it is exactly what I'm looking for.
As an idea probably I can create a special product with specific slug or title and the corresponding script with pre_get_posts hook will find this post/product and modify it to look like I need. I'm looking for some code/ideas how to insert this specific block/page/post into the archive-product page on some position in the grid. Thanks!
Thanks for help, guys! I've implemented the functionality I was looking for. I've found the corresponding loop in archive-product.php and as was suggested by JapanGuy, I've added a simple "if i equal let's say 5 then echo < li>[Custom block]< /li>" .
The original snippet from archive-product.php:
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
Modified code with inserted custom block:
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ($i == 5) {
echo "<li>[Custom block]</li>";
}
$i++;
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
Im such simple way I can add any content to the created [Custom block] and have an usual products grid with extra custom designed block. I'm not very experienced programmer, so probably my code is not perfect, but it works. Thanks!
Edit: Previous code was wrong, changed it here
$i=0;
while ($row = mysqli_fetch_array($query))
{
if ($i == 2) {
echo "Cusom block";
}
echo "<p> Product block " . $row['column'] . " </p>";
$i++;
}
Creating WordPress Custom Post Archives : Hope this meets your requirement.
Custom Post Archives list your custom content. You probably already know the standard WordPress archives. So you can follow this to display both together .
Ref here : https://wp-types.com/documentation/user-guides/creating-wordpress-custom-post-archives/

How to strip HTML from WooCommcerce Archive Description

In WooCommerce, my theme displays descriptions for categories, archives, etc. I am trying to strip HTML from one of them, which is the WooCommerce Archive Description. The description is called with:
<?php endif; ?>
<?php do_action( 'woocommerce_archive_description' ); ?>
<?php if ( have_posts() ) : ?>
I need to apply the wp_strip_all_tags function to the do_action... is that possible? I know this is wrong, but something like:
<?php do_action( wp_strip_all_tags('woocommerce_archive_description') ); ?>
You need to strip the tags in each of the functions attached to that action. Search your theme and plugins to find the functions. For instance, in woocommerce 2.0.20 there are two - woocommerce_taxonomy_archive_description and woocommerce_product_archive_description. Since those function declarations have a check to see if they exist, you could override them by adding your own with the same name in the theme.
What you could do is to replace:
<?php do_action( 'woocommerce_archive_description' ); ?>
with:
<?php echo $queried_object->description; ?>
I prefer to do it like this:
<?php echo '<h2 class="term-description">' . $queried_object->description . '</h2>'; ?>
Because I want to get rid of the paragraph tags surrounding the description and I want to replace the DIV whose class is "term-description" with an H2 and I'm fine to retain the original class.
Enjoy!
Kind Regards,
Mihai Bocsaru

Calling sidebars in wordpress

Hi i am trying to use two different sidebars for both pages and posts.
For that I have used the following condition to test if it is a page (if yes call "sidebar-15" otherwise call "blog").
<?php
if (is_page()){
dynamic_sidebar( 'sidebar-15' );
}
else {
get_sidebar( 'blog' );
}
?>
But, on pages it is still calling blog side bar. Is there something that I am doing wrong?
get_sidebar function
<?php get_sidebar( $name_of_sidebar_file ); ?>
for example:
files: sidebar-right.php and sidebar-left.php
calling:
get_sidebar('right');
get_sidebar('left');

Categories