Wordpress & Genesis Framework linking - php

I created a Page in wordpress called add-a-contact. Contains name, email, and phone number.
I created a custom php page called contact-insert.php which will accept the form fields and insert into a database.
How do I link the Page add-a-contact so when the submit button is clicked it posts to contact-insert.php
I was asked to take over from a previous developer and haven't figured out how Genesis and Word Press are linked together. I was told I can't put the source in functions.php.
Was wondering if anyone could shed some light on this?
Jim

If I understand correctly. You want to have your add-a-contact WordPress Page, have its own php code applied, in WordPress we call it custom page template.
You said, you created a page called contact-insert.php. I would suggest to turn it into a simple page template in your Genesis child theme.
For sample code of how a custom page template looks like in genesis child theme, have a look in this tutorial http://www.wpmayor.com/creating-custom-template-in-genesis-framework/
To create custom template in Genesis you only need few things to do it right.
Put all your code in a function, and then hook that function to some hook, in our case, I suggest do it to genesis_loop
May remove the default loop from that page
Last line of the php file should have genesis(); so it inherit everything from Genesis to become part of Genesis theme.
e.g.
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );
function child_do_custom_loop() {
//your custom php code here
}
Then apply this template your add-a-contact page from custom page template setting https://en.support.wordpress.com/pages/page-attributes/#template

While I would definitely recommend Mohsin's approach, a simpler answer would be to have your contact form's action attribute point to the URL of your custom .php page, so that on submission, custom page can read values from the $_POST superglobal (or via filter_input() if you're feeling fancy).

Related

How can i have a pagination on my wordpress website

I'm trying to have a pagination on my custom Products page that is not the default one in Woocommerce.
I used Elementor to customize this page and after some research I saw that I could call a function that is already integrated in WordPress using the < paginate_links > function.
The only problem is that I have no idea where to call this function in order to have a pagination on my product page.
To be more precise, i would like to know where exactly i have to change or add my php functions, and what code should i use to get my pagination.
Normally it is in the archive.php or a version of that file name specific to your post-type. But before you go and change it, create a child theme in case you haven't done that already. In the child theme folder, you then duplicate the archive.php or similar to make it overwrite the one from the parent theme. This way you keep your version of the theme clean and updatable without losing any changes.
(For creating a child-theme you will need to create at least a style.css [with a WordPress-specific comment, you can google] and a functions.php-file that needs a bit of php-code to enqueue the child-themes scripts and styles. The code for the functions.php can also be found by a quick google search. You then just place the style.css and the functions.php into a new folder you name in the pattern [foldername of your themes name]-child. You then place this folder next to the parent-themes folder in the "/wp-content/themes/"-directory.)
And here you go for the pagination: https://codex.wordpress.org/Pagination

Wordpress - Adding custom Templates for Posts

I'm using different page-templates this for pages.
Now I need the same for posts.
Since 4.7 this should be a core functionality.
So I pretty much followed this quick tutorial and added a custom single-duplicate.php in my theme folder and added this code at the top:
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
However upon creating a new post I dont see the "Post Attributes" Box with the Template-dropdown. What do I do now? Is it possible that my theme somehow prevents that?
Here's my themes functions.php as a gist, if that helps.
I think you are a bit confused as to what Page Attributes will give you access to. To the best of my knowledge, you do not get a drop down to choose a template (as you do on Pages) as an automatic function on posts/custom post types.
you need to create a single-{POSTTYPE}.php in your theme directory and need to add/follow the HTML structure of your page template.
For more information,
Custom Post Type page template doesn't show up
Post Template Files
Hope this will helps you.

Plugin disappears on frontend after theme changing

I am developing a plugin for Woocommerce. I thought it would be nice if the plugin looked nice in different themes. So I downloaded a theme and installed and activated it.
So I checked the plugin on the product page. But it wasn't there!
I changed back to some other theme and it showed up again!
So my question is, is this my fault for developing a not-so dynamic plugin?
Or is this the fault of the theme creator?
And what are the possible explanations/solutions for those kind of problems?
Example:
Twenty fifteen:
Other theme:
The elements of my plugin are not there as far as I've seen.
Edit
I am using the woocommerce_after_main_content hook.
Which I do like this:
add_action( 'woocommerce_after_main_content', 'ws_action_woocommerce_after_main_content', 10);
This calls my function which runs a shortcode.
Like this:
function ws_action_woocommerce_after_main_content() {
do_shortcode('[ws_frame]');
}
This shortcode ofcourse has the function with <h1>Hello, I'm here!</h1>
Summary of how my plugin works
My plugin is a designer plugin for shirts (May aswell be for other products).
The plugin has an options page in the backend.
My plugin only gets loaded if Woocommerce is active. Also, the plugin only gets shown on the product page IF the product is in the specified category.
Using shortcodes, the front end layout is generated in a function, where some enqueued scripts and css is present. The function also has some HTML.
As mentioned above, I am using woocommerce_before_main_content hook. This calls a function which has the do_shortcode('[ws_frame]') in it. This shortcode as the enqueued scripts, css and has some HTML. Yet, I do have ob_flush(); before the do_shortcode('[ws_frame]'). So this might be something?
Also, there isn't much more going on for the front end of this plugin. This is what have done to make it appear on the product page. The options page in the admin panel still works.
The question still remains, is it me, who needs to fix this, or is this something the theme creator is responsible for?
And how can I fix this myself? How can I make sure all of the hooks I'm using are still available in that theme? Even if it is the theme's creators fault, I would like to know how I can fix this myself.
I may be wrong but I guess in your case the theme for which your plugin is not displayed has the particular action removed. (you may check that in the respective theme's functions file.) Well, it is better idea to hook your plugin (functionality related into some action hook which is related to functionality or which renders some funcitonality (rather than being an UI related action).
Like, the action you have used to hook your plugin woocommerce_after_main_content along with another action, only outputs an html element wrapper. (which some themes might remove and use their custom html wrapper.
In your case since your plugin is related to / displayed on single product page, I would recommend to use relevant action to hook your plugin. e.g. woocommerce_after_single_product_summary or woocommerce_after_single_product, which are generally not removed by woocommerce compatible themes.
Hope this helps.

How to make Wordpress Custom page

i m a newbie to wordpress. I have started theme development and encountered these problems. I think these kind of problem does have a solution, but i m not able to find it out.
I m trying to make a custom page. Uptill now i have made header, footer and main index page.
I see that whenever my theme is activated, I see these default index page, with header and footer assign to it.
I have also made some cutom about us , contact us pages using the Add Pages Functionality of wordpress.
My Problem:
1.Now I m trying to make custom product page where I will have more than 100 images on that pages, and then i can change the images, add the images and description and the link url in future. I have made some html code and put it in the text Tab . I can also see the images on the frontend of the Custom page. But my template breaks. Images goes up and description goes far below.
Also i wanted to add fancybox to all the images which are goin to be replaced or added. But again my template breaks.
So can we make custom.php page and do some coding or anything which you feel is the right way of doing it, Please let me know.
Firstly create product.php page in templates folder using below code on top
<?php
/*
Template Name: My Product Page
*/
get_header();
// write your code here
get_footer();
Then, assign the above template to the page in admin.
Then, that page you can call in menu.
For more detail, check here :- http://codex.wordpress.org/Page_Templates
Actually you don't really need to create a custom template for this unless if you are planing to use that same template on another page.
If your page name is products , just create a file called page-products.php in your theme root. and write your code inside that page.
If your planing to develop themes first be comfirtable with wp template hierarchy.
http://codex.wordpress.org/Template_Hierarchy

How to place plugin hook in a wordpress template

In many WordPress plugins, there are instructions that Place <?php do_action('plugin_name_hook'); ?> in your templates.
where exactly this code needs to be placed and what should be the plugin_name_hook?
hooks are actions performed at a time.
If you want a custom hook then
1.create your custom hook in your plugin or theme's function.php
add_action('my_action','my_function');
function my_function()
{
// do something
}
2.and call it in your template as
do_action('my_action');
and you can read more here
https://codex.wordpress.org/Function_Reference/do_action
I don't really like plugins that you still need to modify your theme's template file manually. What is the use then of a plugin.
To come back to you question though, your do_action() call will need to go in the template where you need to display the output of the plugin. Say it is a plugin that add social share buttons to the content, you will need to add the do_action after the_content() in your template files.
The second part of the question, the plugin_name_hook will be specified by the specific plugin. So far that you have to follow the installation instructions of the plugin

Categories