I created the Form.i click the new link button display only title,did not work include_partial(),
What is the problem? any body plz help me.other module forms works fine.
This is newsuccess.php(template)
<h1>New Album</h1>
<?php include_partial('form', array('editFormFields'=>$editFormFields)) ?>
this is my form.php
<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<form action="<?php echo url_for('album/'. ($form->getObject()->isNew() ?
'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject
()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print
'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()):
?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
<table>
<tfoot>
<tr>
<td colspan="2">
<a href="<?php
echo url_for('album/index') ?>">Back to list</a>
<?php if (!$form-
>getObject()->isNew()): ?>
<?php echo link_to('Delete',
'album/delete?id='.$form->getObject()->getId(), array('method' => 'delete',
'confirm' => 'Are you sure?')) ?>
<?php endif; ?>
<input
type="submit" value="Save" />
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form ?>
</tbody>
</table>
</form>
My apachy error log nothing to display
Plz help me.
name of partials should begin with _, so it should be
_form.php
"The partial file name is _mypartial.php and is looked for in modules/mymodule/templates/" from http://www.symfony-project.org/api/1_4/PartialHelper#method_include_partial
Related
I'm attempting to override WooCommerce>Templates>downloads.php to display a custom table that shows the links for multiple downloadable file types in a single row.
My current code is as follows:
'''
<?php
$downloads = WC()->customer->get_downloadable_products();
$has_downloads = (bool) $downloads;
<?php do_action( 'woocommerce_before_account_downloads', $has_downloads ); ?>
<table>
<thead>
<tr>
<th>Title</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<tr>
<td>
<a class="productLink" href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php the_title(); ?>
</a>
</td>
<td>
/*This is the bit that doesn't work*/
<?php
$files = $product->get_downloads();
foreach( $files as $key => $each_download ) {
echo 'File Name | ';
}
?>
</td>
</tr>
<?php endwhile; wp_reset_query(); // Remember to reset ?>
</tbody>
</table>
'''
I'm struggling with how to show the downloadable file links with the filenames visible and separated by a vertical line | .
I can't seem to understand how to create a form with the Wordpress Settings API that only includes a textbox where the user can insert some code and then click a button that says "Save Changes" For reference I am going for something like this:
Insert Headers an Footers Plugin Screenshot
My current code: https://paste.fedoraproject.org/paste/l8JjhNYvp6NPFG1saEsc4Q
This is one example of creating an options page: https://codex.wordpress.org/Creating_Options_Pages
<?php
// create custom plugin settings menu
add_action('admin_menu', 'my_cool_plugin_create_menu');
function my_cool_plugin_create_menu() {
//create new top-level menu
add_menu_page('My Cool Plugin Settings', 'Cool Settings', 'administrator', __FILE__, 'my_cool_plugin_settings_page' , plugins_url('/images/icon.png', __FILE__) );
//call register settings function
add_action( 'admin_init', 'register_my_cool_plugin_settings' );
}
function register_my_cool_plugin_settings() {
//register our settings
register_setting( 'my-cool-plugin-settings-group', 'new_option_name' );
register_setting( 'my-cool-plugin-settings-group', 'some_other_option' );
register_setting( 'my-cool-plugin-settings-group', 'option_etc' );
}
function my_cool_plugin_settings_page() {
?>
<div class="wrap">
<h1>Your Plugin Name</h1>
<form method="post" action="options.php">
<?php settings_fields( 'my-cool-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">New Option Name</th>
<td><input type="text" name="new_option_name" value="<?php echo esc_attr( get_option('new_option_name') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Some Other Option</th>
<td><input type="text" name="some_other_option" value="<?php echo esc_attr( get_option('some_other_option') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Options, Etc.</th>
<td><input type="text" name="option_etc" value="<?php echo esc_attr( get_option('option_etc') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
You can also use another method an use functions add_settings_section and add_settings_field which both need a callback function: http://qnimate.com/wordpress-settings-api-a-comprehensive-developers-guide/
I have created a child theme for twenty-seventeen in wordpress and created a slider function to display slider images and also a custom post type for the function.
Now I created an extra menu under appearances in dashboard as Slider settings and I need to manage the slider using that settings.
In that settings I need to have the following
o Enable slider option (check box)
o Enable slider only for logged in users (check box)
o Set a global title for slider block (text field)
I Added in back end but no condition added in front end to display slides based on this.
How could I do this?
You can use this code and change page for rendering options:
<?php
add_action('admin_menu', 'create_menu');
function create_menu() {
add_options_page(__( 'Plugin Settings', 'textdomain' ),__( 'Plugin Settings', 'textdomain' ), 'administrator', __FILE__, 'settings_page', __FILE__);
add_action( 'admin_init', 'mysettings' );
}
function mysettings() {
register_setting( 'settings-group', 'enable_slider' );
register_setting( 'settings-group', 'enable_slider_loggedin' );
register_setting( 'settings-group', 'slider_title' );
}
function settings_page() {
?>
<div class="wrap">
<h2><?php _e('PluginSettings','textdomain'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields( 'settings-group' ); ?>
<?php do_settings_sections( 'settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e(' Enable slider','textdomain'); ?></th>
<td>
<input name="enable_slider" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Enable slider only for logged in users','textdomain'); ?></th>
<td>
<input name="enable_slider_loggedin" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider_loggedin' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Title For Slider','textdomain'); ?></th>
<td><input type="text" name="slider_title" value="<?php echo get_option('slider_title'); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
Using like this:
if ( get_option ('enable_slider') == 1 ) {
// enable
} else {
//disable
}
i create simple plugin , it work in main page , but when i create a link to user go to the another page for see informaation , it show me Fatal error: Uncaught Error: Call to a member function get_results()
my code is :
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM wp_customers");
?>
<body>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $results){
?>
<tr>
<td>
<?php echo $results->id; ?>
</td>
<td>
<?php echo $results->name; ?>
</td>
<td>
<?php echo $results->family; ?>
</td>
<td>
<?php echo $results->numbers; ?>
</td>
<td>
<?php echo $results->tell; ?>
</td>
<?php }?>
</tr>
</table>
You need to check you have not set up the database prefix to something other than 'wp_'.
And if you have wp_ prefix in the database then you have to included wp-load file on the custom page.
require( '/path/to/wp-load.php' );
If it's a plugin then you should encapsulate your code in a function and hook this funtion to the wordpress "init" action, so in your plugin file you should have somthing like this :
function your_function_name_here($some_params){
return "some results";
}
add_action('init', 'your_function_name_here');
How I search my WordPress site pages with search box I placed in my site?
Currently I am using this code.
<form id="searchform" method="get" action="<?php bloginfo('siteurl')?>/" style="margin-left: -43px;">
<input type="text" name="" id="s" class="textbox" placeholder="Search" required/>
<input id="btnSearch" type="submit" name="submit" value="<?php _e('Search'); ?>" />
</form>
I used name="s" but it not do search properly. I want that if user right page1 name search box take it to siteurl/page1 and so for page2 and remaining page.
Thanks in advance
Try this :
function redirect_search() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/").urlencode($_GET['s']));
exit();
}
}
add_action('template_redirect', 'redirect_search' );
Add above code in your functions.php file.
So now when you type something, it will redirect it to that page.
NOTE:If you type something related to the published post, it will redirect to that POST instead of what have you entered.
For example : If I type hello in search box, then it will redirect you to hello world(which is default post that comes during installation of wordpress).
This is what have for you.
<div id="content" class="textbox <?php echo of_get_option('blog_sidebar_pos') ?>">
<?php _e('Search for:',''); ?> "<?php the_search_query(); ?>"
<?php
if (have_posts()) : while (have_posts()) : the_post();
$format = get_post_format();
get_template_part( 'include/'.$format );
if($format == '')
get_template_part( 'include/standard' );
endwhile; else:
?>
<?php echo '<p><strong>' . __('There has been an error.', '') . '</strong></p>'; ?>
<p> <?php _e('return to home page', ''); ?> <?php _e('use the search .', ''); ?></p>
<?php get_search_form(); ?>
</div><!--no-results-->
<?php endif; ?>
<?php get_template_part('include/post'); ?>