- This topic has 21 replies, 4 voices, and was last updated 10 years, 11 months ago by rwendeln.
-
AuthorPosts
-
August 21, 2013 at 2:27 am #3439shawnhoffmanParticipant
I really like the layout for the business page, and I am using it on my homepage for an upcoming website (shawn.mcctraduccion.com) but I want to know if I can also have a second page using the same format, but with different links.
I’ll explain- on the home page, you see the services from the widget as Translation and English Classes… then if you click on What ShawnCanDo > Student Visa Processes you will see another instance of the services widget, with Translation and English classes… I’d like to have different links there- NOT Translation and English classes… maybe there is a way to make a second widget, or a clone of the business page template and then put the widget on that one? I am pretty new to WP but please let me know if it’s possible and I can try to do it step by step.
Thanks so much!
-Shawn
August 21, 2013 at 3:15 am #3441shawnhoffmanParticipantWell – I think I figured it out. I will describe how I did it, and others can comment if that sounds right, if I am going to run into problems, etc…
- Copy of page-template-business.php and change file name to page-template-business2.php
- Copy code in attitude_widgets.php relative to ‘Registering Business Page template sidebar’
- Same thing with content-extensions.php
–> Change all instances of ‘business’ – to ‘business2’
–> Change all instances of ‘business’ – to ‘business2’ in the copied section
Seems to be working (http://shawn.mcctraduccion.com).
You can see that if you click on ‘What ShawnCanDo’ > ‘Student Visa Processes’ you are taken to a page where you see the 3 services (NIE/TIE, NIE renewal, autorizacion…). Which is from the 2nd widget, and different from the services on the home page.
If anybody can see why this would be a problem, or if there are any other files that I would need to edit, PLEASE TELL ME! If not, I hope this is useful for somebody else!
-Shawn
August 22, 2013 at 10:07 am #3477Sanjip ShahParticipant@shawnhoffman All you have done is good. But please make a child theme to make this customization so that you won’t lose the changes when you update the theme.
August 22, 2013 at 7:34 pm #3499shawnhoffmanParticipantCool! Thanks!
August 22, 2013 at 8:07 pm #3501shawnhoffmanParticipantSo, I am learning about child themes – and I See to add:
require_once( get_stylesheet_directory() . '/my_included_file.php' );
To the style.css of the child theme.
In this case, it will be page-template-business2.php, attitude_widgets.php, & content-extensions.php
Do I need to put them in the corresponding subdirectories, or just into the theme directory.
i.e. do the files need to be/attitude-child/page-template-business2.php
/attitude-child/library/widgets/attitude_widgets.php
/attitude-child/library/structure/content-extensions.phpor simply
/attitude-child/page-template-business2.php
/attitude-child/attitude_widgets.php
/attitude-child/content-extensions.phpThanks!
August 22, 2013 at 9:10 pm #3503shawnhoffmanParticipantUfff now I am having problems…
You can see what it looks like now at the same site…
I put the files in their respective folders, which seems right…
However, I am not sure if the files
a) need to be edited more to reflect “attitude-child” and not “attitude”
b) need to be the whole file with my additions, or only the new additionsHELP?!?! Thank you!!
August 22, 2013 at 10:33 pm #3505shawnhoffmanParticipantWell, I think that require line doesn’t go in the style.css file – but rather is php … but I still don’t know where/how to do it 🙁
August 23, 2013 at 12:14 am #3506shawnhoffmanParticipantWow that was such a long process of trying, failing, changing and repeating, but with almost no experience with php and never having used functions.php or anything with child themes I think I finally figured it out. Please let me know if I “overcorrected” or did something wrong or still need to do something. Seems to be functioning at this point.
For the page_template_business2.php, it was sufficient to only put it in the child theme directory.
For the other two, I created functions.php in the child theme and added the necessary code below. My questions that remain:
1) Was it necessary to remove the action, and add a new one, or could I have added to the existing action? From what I read, it was necessary to delete the old stuff, but then copy them into the new action in order to maintain the other native widgets.
2) Was it necessary to name the function _child or could I have not done that?
3) Was there any use for that require_once line?? Cause I deleted it and don’t see where it would be necessary.
Here’s the code from functions.php and I obviously deleted all the other junk from my previous posts.
<?php remove_action( 'widgets_init', 'attitude_widgets_init' ); function attitude_child_widgets_init() { // Registering main left sidebar register_sidebar( array( 'name' => __( 'Left Sidebar', 'attitude' ), 'id' => 'attitude_left_sidebar', 'description' => __( 'Shows widgets at Left side.', 'attitude' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); // Registering main right sidebar register_sidebar( array( 'name' => __( 'Right Sidebar', 'attitude' ), 'id' => 'attitude_right_sidebar', 'description' => __( 'Shows widgets at Right side.', 'attitude' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); // Registering Business Page template sidebar register_sidebar( array( 'name' => __( 'Business Page Sidebar', 'attitude' ), 'id' => 'attitude_business_page_sidebar', 'description' => __( 'Shows widgets on Business Page Template. Sutiable widget: Theme Horse: Featured widget, Theme Horse: Testimonial, Theme Horse: Services', 'attitude' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>' ) ); // Registering Business2 Page template sidebar register_sidebar( array( 'name' => __( 'Business2 Page Sidebar', 'attitude' ), 'id' => 'attitude_business2_page_sidebar', 'description' => __( 'Shows widgets on Business2 Page Template. Sutiable widget: Theme Horse: Featured widget, Theme Horse: Testimonial, Theme Horse: Services', 'attitude' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>' ) ); // Registering contact Page sidebar register_sidebar( array( 'name' => __( 'Contact Page Sidebar', 'attitude' ), 'id' => 'attitude_contact_page_sidebar', 'description' => __( 'Shows widgets on Contact Page Template.', 'attitude' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); // Registering footer sidebar register_sidebar( array( 'name' => __( 'Footer Sidebar', 'attitude' ), 'id' => 'attitude_footer_sidebar', 'description' => __( 'Shows widgets at footer.', 'attitude' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); // Registering widgets register_widget( "attitude_custom_tag_widget" ); register_widget( "attitude_service_widget" ); register_widget( "attitude_recent_work_widget" ); register_widget( "attitude_Widget_Testimonial" ); } add_action( 'widgets_init', 'attitude_child_widgets_init' ); add_action( 'attitude_business2_template_content', 'attitude_business2_template_widgetized_content', 10 ); /** * Displays the widget as contents */ function attitude_business2_template_widgetized_content() { ?> <div id="content"> <?php if( is_active_sidebar( 'attitude_business2_page_sidebar' ) ) { // Calling the footer sidebar if it exists. if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'attitude_business2_page_sidebar' ) ): endif; } ?> </div><!-- #content --> <?php } ?>
August 27, 2013 at 7:28 am #3613Sanjip ShahParticipant@shawnhoffman All you have done is perfect. You could also do as follows as another way. Just add your new sidebar only in the functions.php file without removing the parent sidebars, widgets and again adding them. Try this out as well and see if this works.
Q1) If you do like this then you don’t have to remove the action and again add it. Adding the code below will just append your new sidebar.
Q2) Adding _child is just a way to use a different function name, if you use the same function name attitude_widgets_init in the child theme then their will be same function definition in two places one in parent theme and one in child theme. This function is not pluggable function so adding this in child theme will not overwrite the parent function. So, using same name in this case will cause problem.
Q3) Require once code will be unnecessary after you do as you done now.<?php; function attitude_child_widgets_init() { // Registering Business2 Page template sidebar register_sidebar( array( 'name' => __( 'Business2 Page Sidebar', 'attitude' ), 'id' => 'attitude_business2_page_sidebar', 'description' => __( 'Shows widgets on Business2 Page Template. Sutiable widget: Theme Horse: Featured widget, Theme Horse: Testimonial, Theme Horse: Services', 'attitude' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>' ) ); } add_action( 'widgets_init', 'attitude_child_widgets_init' ); add_action( 'attitude_business2_template_content', 'attitude_business2_template_widgetized_content', 10 ); /** * Displays the widget as contents */ function attitude_business2_template_widgetized_content() { ?> <div id="content"> <?php if( is_active_sidebar( 'attitude_business2_page_sidebar' ) ) { // Calling the footer sidebar if it exists. if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'attitude_business2_page_sidebar' ) ): endif; } ?> </div><!-- #content --> <?php } ?>
November 21, 2013 at 1:18 am #5252siredgarParticipantis it possible to have a third business page? please could you tell me what the code forthe functions.php will be? I have tried having the code above twice, once for business2 and once for business3 along with adding the page-template-business2.php and page-template-business3.php files but it only shows business2 widget. Thank you!
November 22, 2013 at 6:37 am #5297Sanjip ShahParticipant@siredgar If you repeat the above mentioned process for the third time properly then yes you can have the third business page as well. Please paste the code that you have added in the functions.php and I will look into it if there are any issues.
November 22, 2013 at 1:48 pm #5308siredgarParticipantThanks Sanjip, I have managed to get it working using the following in the functions.php of the childtheme. I had the order wrong before, seems to be correct now? Thank you
<?php; function attitude_child_widgets_init() { // Registering Business2 Page template sidebar register_sidebar( array( 'name' => __( 'Business2 Page Sidebar', 'attitude' ), 'id' => 'attitude_business2_page_sidebar', 'description' => __( 'Shows widgets on Business2 Page Template. Sutiable widget: Theme Horse: Featured widget, Theme Horse: Testimonial, Theme Horse: Services', 'attitude' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>' ) ); } { // Registering Business3 Page template sidebar register_sidebar( array( 'name' => __( 'Business3 Page Sidebar', 'attitude' ), 'id' => 'attitude_business3_page_sidebar', 'description' => __( 'Shows widgets on Business3 Page Template. Sutiable widget: Theme Horse: Featured widget, Theme Horse: Testimonial, Theme Horse: Services', 'attitude' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>' ) ); } add_action( 'widgets_init', 'attitude_child_widgets_init' ); add_action( 'attitude_business2_template_content', 'attitude_business2_template_widgetized_content', 10 ); /** * Displays the widget as contents */ function attitude_business2_template_widgetized_content() { ?> <div id="content"> <?php if( is_active_sidebar( 'attitude_business2_page_sidebar' ) ) { // Calling the footer sidebar if it exists. if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'attitude_business2_page_sidebar' ) ): endif; } ?> </div><!-- #content --> add_action( 'attitude_business3_template_content', 'attitude_business3_template_widgetized_content', 10 ); /** * Displays the widget as contents */ function attitude_business3_template_widgetized_content() { ?> <div id="content"> <?php if( is_active_sidebar( 'attitude_business3_page_sidebar' ) ) { // Calling the footer sidebar if it exists. if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'attitude_business3_page_sidebar' ) ): endif; } ?> </div><!-- #content --> <?php } ?>
November 25, 2013 at 7:37 am #5344Sanjip ShahParticipant@siredgar Okay. Great.
November 25, 2013 at 10:55 am #5360siredgarParticipant@sanjip-shah Hi Sanjip, The code unfortunately displays the business3 links on the business2 page. Is there a problem with the php above? thank you!
November 25, 2013 at 11:48 am #5361Sanjip ShahParticipant@siredgar Did you create this file page_template_business3.php and write the corresponding code. Please paste the complete code of this file and I will look into it.
-
AuthorPosts
- You must be logged in to reply to this topic.