Community Forums › Forums › Archived Forums › Design Tips and Tricks › How get features of custom frontpage to custom-blog-page?
Tagged: page_blog.php
- This topic has 7 replies, 2 voices, and was last updated 6 years, 11 months ago by Dan-cer.
-
AuthorPosts
-
May 16, 2017 at 6:52 am #206538Dan-cerMember
Hi, I'm using Lifestyle Pro theme and a frontpage with a few widget areas - home top, home middle, home bottom left, home bottom right
before the loop.
I want to set the frontpage to static and move the blog to a page named "Blog". This blog should also have the widget areas as it is set for frontpage.
In functions.php I have already registered the new widget areas - blog top, blog middle, blog bottom, ...
But I didn't succeed in doing the specific settings in the page_blog.php.Please check where there is a mistake.
Here are the 3 files:
1. functions.php<?php //* Start the engine include_once( get_template_directory() . '/lib/init.php' ); //* Setup Theme include_once( get_stylesheet_directory() . '/lib/theme-defaults.php' ); //* Set Localization (do not remove) load_child_theme_textdomain( 'lifestyle', apply_filters( 'child_theme_textdomain', get_stylesheet_directory() . '/languages', 'lifestyle' ) ); //* Child theme (do not remove) define( 'CHILD_THEME_NAME', __( 'Lifestyle Pro Theme', 'lifestyle' ) ); define( 'CHILD_THEME_URL', 'http://my.studiopress.com/themes/lifestyle/' ); define( 'CHILD_THEME_VERSION', '3.1' ); //* Add HTML5 markup structure add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) ); //* Add viewport meta tag for mobile browsers add_theme_support( 'genesis-responsive-viewport' ); //* Enqueue Scripts add_action( 'wp_enqueue_scripts', 'lifestyle_load_scripts' ); function lifestyle_load_scripts() { wp_enqueue_script( 'lifestyle-responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' ); wp_enqueue_style( 'dashicons' ); wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Droid+Sans:400,700|Josefin+Sans:400,600|Roboto+Slab:400,300,700', array(), CHILD_THEME_VERSION ); } //* Enqueue sticky menu script add_action( 'wp_enqueue_scripts', 'custom_enqueue_script' ); function custom_enqueue_script() { wp_enqueue_script( 'sticky-menu', get_stylesheet_directory_uri() . '/js/sticky-menu.js', array( 'jquery' ), '', true ); } //* Add new image sizes add_image_size( 'home-large', 500, 281, TRUE ); add_image_size( 'middle', 400, 225, TRUE ); add_image_size( 'home-small', 330, 185, TRUE ); add_image_size( 'full-width', 1200, 800, TRUE ); add_image_size( 'related', 90, 70, true ); //* Add support for custom background add_theme_support( 'custom-background', array( 'default-image' => get_stylesheet_directory_uri() . '/images/bg.png', 'default-color' => 'efefe9', ) ); //* Add support for custom header add_theme_support( 'custom-header', array( 'header_image' => '', 'header-selector' => '.site-title a', 'header-text' => false, 'height' => 328, 'width' => 1200, 'flex-height' => true, ) ); //* Add support for additional color style options add_theme_support( 'genesis-style-selector', array( 'lifestyle-pro-blue' => __( 'Lifestyle Pro Blue', 'lifestyle' ), 'lifestyle-pro-green' => __( 'Lifestyle Pro Green', 'lifestyle' ), 'lifestyle-pro-mustard' => __( 'Lifestyle Pro Mustard', 'lifestyle' ), 'lifestyle-pro-purple' => __( 'Lifestyle Pro Purple', 'lifestyle' ), 'lifestyle-pro-red' => __( 'Lifestyle Pro Red', 'lifestyle' ), ) ); //* Reposition the primary navigation remove_action( 'genesis_after_header', 'genesis_do_nav' ); add_action( 'genesis_before_header', 'genesis_do_nav' ); /* Enqueue sticky menu script add_action( 'wp_enqueue_scripts', 'sp_enqueue_script' ); function sp_enqueue_script() { wp_enqueue_script( 'sample-sticky-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/sticky-menu.js', array( 'jquery' ), '1.0.0' ); */ //* Reposition the secondary navigation menu remove_action( 'genesis_after_header', 'genesis_do_subnav' ); //add_action( 'genesis_before', 'genesis_do_subnav' ); //* Modify the size of the Gravatar in the author box add_filter( 'genesis_author_box_gravatar_size', 'lifestyle_author_box_gravatar' ); function lifestyle_author_box_gravatar( $size ) { return 96; } add_filter( 'the_content', function( $content ) { remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 ); return $content . wp_link_pages( array( 'echo' => FALSE ) ); }, -1 ); //* Modify the size of the Gravatar in the entry comments add_filter( 'genesis_comment_list_args', 'lifestyle_comments_gravatar' ); function lifestyle_comments_gravatar( $args ) { $args['avatar_size'] = 60; return $args; } //* Remove comment form allowed tags add_filter( 'comment_form_defaults', 'lifestyle_remove_comment_form_allowed_tags' ); function lifestyle_remove_comment_form_allowed_tags( $defaults ) { $defaults['comment_notes_after'] = ''; return $defaults; } //* Add support for 3-column footer widgets add_theme_support( 'genesis-footer-widgets', 3 ); //* Add support for after entry widget add_theme_support( 'genesis-after-entry-widget-area' ); //* Relocate after entry widget remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' ); add_action( 'genesis_after_entry', 'genesis_after_entry_widget_area', 5 ); //* Register widget areas genesis_register_sidebar( array( 'id' => 'home-top', 'name' => __( 'Home - Top', 'lifestyle' ), 'description' => __( 'This is the top section of the homepage.', 'lifestyle' ), ) ); genesis_register_sidebar( array( 'id' => 'home-middle', 'name' => __( 'Home - Middle', 'lifestyle' ), 'description' => __( 'This is the middle section of the homepage.', 'lifestyle' ), ) ); genesis_register_sidebar( array( 'id' => 'home-bottom-left', 'name' => __( 'Home - Bottom Left', 'lifestyle' ), 'description' => __( 'This is the bottom left section of the homepage.', 'lifestyle' ), ) ); genesis_register_sidebar( array( 'id' => 'home-bottom-right', 'name' => __( 'Home - Bottom Right', 'lifestyle' ), 'description' => __( 'This is the bottom right section of the homepage.', 'lifestyle' ), ) ); //* für Blog-Seite genesis_register_sidebar( array( 'id' => 'blog-top', 'name' => __( 'Blog - Top', 'lifestyle' ), ) ); genesis_register_sidebar( array( 'id' => 'blog-middle', 'name' => __( 'Blog - Middle' ), ) ); genesis_register_sidebar( array( 'id' => 'blog-bottom-left', 'name' => __( 'Blog - Bottom Left' ), ) ); genesis_register_sidebar( array( 'id' => 'blog-bottom-right', 'name' => __( 'Blog - Bottom Right' ), ) ); //** für Category Verjüngung genesis_register_sidebar( array( 'id' => 'before-loop-verjuengung', 'name' => __( 'Before Category Verjuengung' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-verjuengung', 'name' => __( 'After Category Verjuengung' ), ) ); //** für Category Medien genesis_register_sidebar( array( 'id' => 'before-loop-medien', 'name' => __( 'Before Category Medien' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-medien', 'name' => __( 'After Category Medien' ), ) ); //*für Category HeilSein genesis_register_sidebar( array( 'id' => 'before-loop-heilsein', 'name' => __( 'Before Category HeilSein' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-heilsein', 'name' => __( 'After Category HeilSein' ), ) ); //*für Category Ernährung genesis_register_sidebar( array( 'id' => 'before-loop-ernaehrung', 'name' => __( 'Before Category Ernaehrung' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-ernaehrung', 'name' => __( 'After Category Ernaehrung' ), ) ); //*für Category Macht der Gedanken genesis_register_sidebar( array( 'id' => 'before-loop-gedankenkraft', 'name' => __( 'Before Category Macht der Gedanken' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-gedankenkraft', 'name' => __( 'After Category Macht der Gedanken' ), ) ); //*Custom title add_filter( 'genesis_seo_title', 'custom_title', 10, 3 ); function custom_title( $title, $inside, $wrap ) { $cf = get_post_meta( get_the_ID(), 'custom-title', true ); $ternary = is_singular(array( 'post','page' ) ) && $cf ? $cf : get_bloginfo( 'name' ); $inside = sprintf( '<a href="%s">%s</a>', trailingslashit( home_url() ), $ternary ); $title = genesis_markup( array( 'open' => sprintf( "<{$wrap} %s>", genesis_attr( 'site-title' ) ), 'close' => "</{$wrap}>", 'content' => $inside, 'context' => 'site-title', 'echo' => false, 'params' => array( 'wrap' => $wrap, ), ) ); return $title; } function new_excerpt_more( $more ) { return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>'; } add_filter( 'excerpt_more', 'new_excerpt_more' ); //* Exclude Categories from Category Widget - basicWP.com function custom_category_widget($args) { $exclude = "1"; // Category IDs to be excluded $args["exclude"] = $exclude; return $args; } add_filter("widget_categories_args","custom_category_widget"); // Genesis Default Responsive Menu //include_once( get_stylesheet_directory() . '/lib/responsive-menu.php' ); // Remove Footer remove_action('genesis_footer', 'genesis_do_footer'); remove_action('genesis_footer', 'genesis_footer_markup_open', 5); remove_action('genesis_footer', 'genesis_footer_markup_close', 15); //*add_filter('show_admin_bar', '__return_true'); //* Create custom category archive widget area genesis_register_sidebar( array( 'id' => 'category-widget', 'name' => __( 'Category Page Widget', 'lifestyle' ), 'description' => __( 'This is the widget section of category pages.', 'lifestyle' ), ) ); //* Hook category widget area before post content add_action( 'genesis_before_content', 'lifestyle_category_archive_widget' ); function lifestyle_category_archive_widget() { if ( is_category( ) ) genesis_widget_area( 'category-widget', array( 'before' => '<div class="category-widget widget-area">', 'after' => '</div>', ) ); } /** Exclude certain category from posts */ add_action( 'pre_get_posts', 'be_exclude_category_from_blog' ); function be_exclude_category_from_blog( $query ) { if( $query->is_main_query() && $query->is_home() ) { $query->set( 'cat', '-14610' ); } } genesis_register_sidebar( array( 'id' => 'before-loop-medien', 'name' => __( 'Before Category Medien' ), ) ); genesis_register_sidebar( array( 'id' => 'after-loop-medien', 'name' => __( 'After Category Medien' ), ) ); add_filter('relevanssi_remove_punctuation', 'ss_conversion', 9); function ss_conversion($a) { $a = str_replace('ß', 'ss', $a); return $a; } add_filter('relevanssi_remove_punctuation', 'ae_conversion', 9); function ae_conversion($a) { $a = str_replace('ä', 'ae', $a); return $a; } add_filter('relevanssi_remove_punctuation', 'oe_conversion', 9); function oe_conversion($a) { $a = str_replace('ö', 'oe', $a); return $a; } add_filter('relevanssi_remove_punctuation', 'ue_conversion', 9); function ue_conversion($a) { $a = str_replace('ü', 'ue', $a); return $a; }
2. front-page.php (already modified and working)
<?php /** * This file adds the Home Page to the Lifestyle Pro Theme. * * @author StudioPress * @package Lifestyle Pro * @subpackage Customizations */ add_action( 'genesis_meta', 'lifestyle_home_genesis_meta' ); /** * Add widget support for homepage. If no widgets active, display the default loop. * */ function lifestyle_home_genesis_meta() { if ( is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-bottom-left' ) || is_active_sidebar( 'home-bottom-right' ) ) { // Force content-sidebar layout setting add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); // Add lifestyle-pro-home body class add_filter( 'body_class', 'lifestyle_body_class' ); // Remove the default Genesis loop remove_action( 'genesis_loop', 'genesis_do_loop' ); // Add homepage widgets add_action( 'genesis_loop', 'lifestyle_homepage_widgets' ); } } function lifestyle_body_class( $classes ) { $classes[] = 'lifestyle-pro-home'; return $classes; } function lifestyle_homepage_widgets() { genesis_widget_area( 'home-top', array( 'before' => '<div class="entry"><div class="home-top widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'home-middle', array( 'before' => '<div class="entry"><div class="home-middle widget-area">', 'after' => '</div>', ) ); if ( is_active_sidebar( 'home-bottom-left' ) || is_active_sidebar( 'home-bottom-right' ) ) { echo '<div class="home-bottom">'; genesis_widget_area( 'home-bottom-left', array( 'before' => '<div class="home-bottom-left widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'home-bottom-right', array( 'before' => '<div class="home-bottom-right widget-area">', 'after' => '</div>', ) ); echo '</div>'; } } genesis();
3. page_blog.php (already modified)
<?php /** Template Name: Custom Blog */ add_action( 'genesis_meta', 'blog_page_genesis_meta' ); /** * Add widget support for homepage. If no widgets active, display the default loop. * */ function blog_page_genesis_meta() { if ( is_active_sidebar( 'blog-top' ) || is_active_sidebar( 'blog-middle' ) || is_active_sidebar( 'blog-bottom-left' ) || is_active_sidebar( 'blog-bottom-right' ) ) { // Force content-sidebar layout setting add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); // Add lifestyle-pro-home body class add_filter( 'body_class', 'blog_page_body_class' ); // Remove the default Genesis loop remove_action( 'genesis_loop', 'genesis_do_loop' ); // Add homepage widgets add_action( 'genesis_loop', 'blog_page_widget' ); } } add_filter( 'body_class', 'blog_page_body_class' ); function blog_page_body_class( $classes ) { $classes[] = 'custom-blog'; return $classes; } add_action( 'genesis_before_loop', 'blog_page_widget' ); function blog_page_widget() { genesis_widget_area( 'blog-top', array( 'before' => '<div class="custom-blog entry"><div class="blog-top widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'blog-middle', array( 'before' => '<div class="custom-blog entry"><div class="blog-middle widget-area">', 'after' => '</div>', ) ); if ( is_active_sidebar( 'blog-bottom-left' ) || is_active_sidebar( 'blog-bottom-right' ) ) { echo '<div class="blog-bottom">'; genesis_widget_area( 'blog-bottom-left', array( 'before' => '<div class="blog-bottom-left widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'blog-bottom-right', array( 'before' => '<div class="blog-bottom-right widget-area">', 'after' => '</div>', ) ); echo '</div>'; } } genesis();
Thank you for your help!
https://www.test.rainerklar.de/blog/May 16, 2017 at 7:21 am #206540Victor FontModeratorYou are removing the loop that displays posts in your blog template. If you want to display the posts, you have to use a different hook for the widgets, like genesis_after_header or genesis_before_loop, then leave the loop in tact. Delete the remove_action for the genesis_loop.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 16, 2017 at 7:59 am #206541Dan-cerMemberThank you Victor.
At the moment the blog page is displaying only the posts. When I click on "Customize" and >Widgets, only the main widget areas are displayed: Header Right, Primary Sidebar, Footer 1,2 and 3.
Missing are Blog Top, Blog Middle, Blog Bottom Left and Blog Bottom Right.I deleted the remove_action for the genesis_loop and modified the hook as you suggested.
Is there anything else wrong? Eventually the first code-lines:
add_action( 'genesis_meta', 'blog_page_genesis_meta' ); function blog_page_genesis_meta() { if ( is_active_sidebar( 'blog-top' ) || is_active_sidebar( 'blog-middle' ) || is_active_sidebar( 'blog-bottom-left' ) || is_active_sidebar( 'blog-bottom-right' ) ) { // Force content-sidebar layout setting add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); } }
Here is the current page_blog.php:
<?php /** Template Name: Custom Blog */ add_action( 'genesis_meta', 'blog_page_genesis_meta' ); function blog_page_genesis_meta() { if ( is_active_sidebar( 'blog-top' ) || is_active_sidebar( 'blog-middle' ) || is_active_sidebar( 'blog-bottom-left' ) || is_active_sidebar( 'blog-bottom-right' ) ) { // Force content-sidebar layout setting add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); } } add_filter( 'body_class', 'blog_page_body_class' ); function blog_page_body_class( $classes ) { $classes[] = 'custom-blog'; return $classes; } add_action( 'genesis_before_loop', 'blog_page_widget' ); function blog_page_widget() { genesis_widget_area( 'blog-top', array( 'before' => '<div class="custom-blog entry"><div class="blog-top widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'blog-middle', array( 'before' => '<div class="custom-blog entry"><div class="blog-middle widget-area">', 'after' => '</div>', ) ); if ( is_active_sidebar( 'blog-bottom-left' ) || is_active_sidebar( 'blog-bottom-right' ) ) { echo '<div class="blog-bottom">'; genesis_widget_area( 'blog-bottom-left', array( 'before' => '<div class="blog-bottom-left widget-area">', 'after' => '</div>', ) ); genesis_widget_area( 'blog-bottom-right', array( 'before' => '<div class="blog-bottom-right widget-area">', 'after' => '</div>', ) ); echo '</div>'; } } genesis();
May 16, 2017 at 9:01 am #206548Victor FontModeratorDid you actually assign the template to the blog page in the page editor? When I view your source code, the custom-blog class is not in the body tag. The template is not being read.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 16, 2017 at 10:11 am #206552Dan-cerMemberYes I have assigned the template blog page: The template is named Custom Blog and I could check it in quick edit. In normal editor I set the sidebar "Blog" which I created before, but then - in "Customize" - the standard sidebar ("Primary Sidebar") is shown.
So you are right - it is not being read. But why?May 16, 2017 at 2:20 pm #206570Victor FontModeratorCaching?
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 16, 2017 at 11:05 pm #206578Dan-cerMemberNo, I cleared all cache often and also tried it out in another browser.
Is this the right code in the beginning of the file:
add_action( 'genesis_meta', 'blog_page_genesis_meta' );
May 18, 2017 at 10:46 am #206659Dan-cerMemberHey Victor, I could solve it! By following these instructions, mainly in the comments at the bottom of the thread.
In short: I renamed page_blog.php to home.php. Thats it!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.