I saw the following answer to the post Where are Magento static CMS blocks stored? regarding programatically using PHP generating cms/blocks in Magento.
I changed the code to the following
$newBlock = Mage::getModel('cms/page')
->setTitle('Test CMS Page Title')
->setContent('Hello I\'m a new cms page.')
->setIdentifier('this-is-the-page-url')
->setIsActive(true)
->save();
... and it works. I see a new page show up in the CMS Pages area in the backend.
What I need to add to this is the ability to set the content of the other fields in the CMS/Page. Namely:
Layout (trying to set to 1 column)
meta keyword
meta description
fields. These fields are blank currently. I so far haven't been able to figure this part out.
Thanks,
here you go:
$cmsPageData = array(
'title' => 'Test CMS Page Title',
'root_template' => 'one_column',
'meta_keywords' => 'meta,keywords',
'meta_description' => 'meta description',
'identifier' => 'this-is-the-page-url',
'content_heading' => 'content heading',
'stores' => array(0),//available for all store views
'content' => "Hello I'm a new cms page."
);
Mage::getModel('cms/page')->setData($cmsPageData)->save();
The keys of the array are the name of the fields of the cms_page table (check the db). And to know the value, I manually create the cms page I want and then see the value for this entry in the db.
Related
I have Drupal 7 site. It has custom content type Product. It has 20 fields. I want to control the UI of the add/edit form for this content type.
I created a module under sites/all/modules.
admin_product
-admin_product.info
-admin_product.module
-admin_product.module
<?php
function admin_product_theme($existing, $type, $theme, $path){
return array(
'product_node_form' => array(
'arguments' => array(
'form' => NULL,
),
'path' => drupal_get_path('theme', 'myTheme').'/templates/forms',
'template' => 'product-node-form',
'render element' => 'form',
)
);
}
In the templates - sites/all/themes/myTheme/templates/forms/product-node-form.tpl.php
-product-node-form.tpl.php
<?php
echo drupal_render_children($form);
echo 'hello template'; // just to test
?>
The template is not rendered.
How do I control the UI of the form.?
Any help highly appreciated.
I think all you need is Field Group module. With the help of this module you can organize all your fields in groups (i.e. divs, tabs etc.). The rest stuff can be made by CSS.
Other way is to use hook_form_FORM_ID_alter() hook, or, specifically, hook_form_node_form_alter(), to alter your form.
Anyway, in Drupal 7 Form API differs from Theme API, and the code you provided just has no sense :) Sorry for this :)
If the theme you're adding this to is not the default admin theme for the site then the template won't get picked up in the admin area.
You'll have to add this code to a custom module or create a sub-theme based on the administrative theme (e.g., Seven) and select that as your admin theme and put the code there.
Good explanation found here: https://drupal.stackexchange.com/questions/33253/how-do-you-theme-a-content-types-create-edit-form-in-drupal-7
I have searched for this topic here and Google but I only found the solutions with PHP frameworks (for example, YII and Laravel)
I am developing a simple CMS and I would like to add widget system just like WordPress ( Recent Comments, Categories widgets )
List available widgets.
Users can active the widgets and use them in sidebar.
My steps:
1. First at all, I already made an admin tool as the screenshot blow ( jQuery UI sortable works fine)
Here is my php code:
$available_widgets = array(
0 => array(
'id' => 'recent-post',
'title' => 'Latest Pots',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
1 => array(
'id' => 'recent-comment',
'title' => 'Recent Commets',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
2 => array(
'id' => 'text-box',
'title' => 'Text Box',
'option' => array('multi_widget' => 1)
)
);
View
foreach ( $available_widgets AS $available_widget ) {
if ( $available_widget['option']['multi_widget'] == 0 ) {
echo '<li class="widget-box widget-single" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
else {
echo '<li class="widget-box widget-multiple" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
}
But I still no idea about the next step, any idea will be grateful.
Thanks.
Update:
For my step 2 I made a simple EventDispatcher, I put the link here if someone else needs it.
https://github.com/terrylinooo/PHP-EventDispatcher
You may be underestimating the complexity of this question. If you are doing this from scratch, there will be several things to consider.
Are you creating all your widgets, and then just want the user to be able to pick and choose which ones they want visible?
If so, roughly I would probably:
Obviously make html sidebar that will house the widgets, styled by your css. Have the width of column set to 0 if no widgets are published.
And of course make all your widgets in separate files probably in their own folder.
Have database table with at very least path to widget file, "published" boolean column, and "widget_order" column.
Choose where in the admin area the user will choose which ones to show, and have it change the "published" column in the table, and maybe also a small text box or dropdown where they can specify the order number.
Then on the front end, just do a database lookup in the sidebar, if the number of rows from the module table that are "published" is greater than 0, then 'echo' out a css value that will give your column the correct width (of your choice) instead of 0 width keeping it hidden otherwise if none are enabled.
The database look up should have the ORDER BY clause to follow the 'widget_order' values. This obviously is how the widgets get displayed in order by the users preference.
Now each widgets functionality is all in each file, so put any relevant php, Javascript etc, in each one which will make them easy to develop and modify. Obviously you can refactor after where feasible.
Hope this gives you an idea of what you're getting in to lol..
Take a look at Observer Pattern
or Event Dispatcher Pattern for plugin system
When installing plugins, don't forget to save it to the database
And, to list available widgets, you just need to query the database which plugins are available or activated.
I'm building a theme options system to my theme using the Redux framework.
I want to append a css property (background-image) when the user press specific button in a "Button Set" field.
The code:
array(
'id' => 'opt_change_menu_button',
'type' => 'button_set',
'title' => __('Change Menu Button', 'faster'),
'options' => array(
'yes' => __('Yes', 'faster'),
'no' => __('No', 'faster'),
),
'defualt' => 'no',
),
When the user press YES, I want, in addition to what already happen (some other options appear in the bottom), to append a CSS property in the front end ( background-image: none), that overwrites the other properties which relate to the chosen selector.
In some other fields it is possible using the "output" value, but in that case I didn't fiend it possible, after hours of struggling.
Thanks in advance!
Lead dev of Redux here. You'll have to append your own JavaScript for in-panel changes via JS. Luckily, it's quite easy. https://docs.reduxframework.com/core/advanced/custom-panel-css/
Ok, I have been looking for hours and I have to say I am really lost. I am trying to create a new section in the admin section of wordpress that should enable the user to create a new custom "office" page.
There is really many office pages on the site I have been working on (over 30), each with its opening hours, map, and images. I assume the client will want to add more later (or remove them) and they would like to manage it through Wordpress. That would mean adding a section that would enable them to put in the name of the office, opening hours, images and the location and it would create a new office page. I am rather a front-end developer and I have never worked with Wordpress before. I understand the loop, etc, I have read several things about Themes and how to create them but I am seriously stuck with how to create a section in admin area that would enable page creation/deletion with certain options.
Any help is greatly appreciated, just please point me to the correct direction. Web pages, WP codex, tutorials, youtube... whatever that helps. Thanks a bunch!
You can make custom post type..
By writing Code in function.php
function function-name(){
register_post_type( 'post name',
array(
'labels' => array(
'name' => __( 'post name' ),
'singular_name' => __( 'post name' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'post name'),
'supports' => array('title','editor','author','thumbnail','comments','custom-fields'),
)
);
}
add_action('init', 'function-name');
3 steps : -
1. create office post type by using Register Post Type
2. Create office categories by using Register taxonomy
3. create a meta box by using Add Meta Box for extra fields which wordpress doesnt offer by default like (office hours )
hope it helps !
Is there any way to create forms for a particular content type and submit it form the site itself. I have 2 content types created in my Wordpress and I want to create a form to post to a particular content type. Also is it possible to create the form as a page in wordpress?
regards - dj
I have used the following method to achieve this:
I have used the shortcode function to create forms in the site. Here you can see the documentation for adding shortcodes. Submit page was also a 'page' with shortcode. So I have collected the values in the shortcode function and added the content to the wp_posts table using wp_insert_post function. You can see the documentation about wp_insert_post() here. I hope this help :)
regards dj
You have to add a function to your functions.php file. Something like this example:
add_action(‘init’, ‘mycustomcontent_init’); //enable custom content types
function mycustomcontent_init() {
// create content type Crafts
$args = array(
‘label’ => __(‘Crafts’), //content type name to be displayed in the wordpress dashboard
‘singular_label’ => __(‘Crafts’), //content type name to be displayed in the wordpress dashboard
‘public’ => true,
‘show_ui’ => true, // show the user interface for this content type? true=yes false=no
‘_builtin’ => false, //declartion to the system that it’s a custom content type and not a built in content type
‘_edit_link’ => ‘post.php?post=%d’,
‘capability_type’ => ‘post’, //set the content type features, here we setting it to the features of a standard post
‘hierarchical’ => false,
‘rewrite’ => array(“slug” => “crafts”), //prefix to the url alias for this content type, eg: mysite.org/crafts/model-ships
‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’)
);
register_post_type( ‘crafts’ , $args );
}
taken from here.
Also, read up on the Wordpress Documentation for Custom Post Types