I have wordpress flash game website. Into the admin panel, where I add or edit post I have field named Swf URL: where I add SWF link and it links to the post where it shows flash game. I want to do same but not in the post, I want to use this function (adding game with the help of swf) to home page.
How it is now:
How I want to see:
functions code:
load_theme_textdomain( "freebabyhazelgames", TEMPLATEPATH."/languages" );
$locale = get_locale( );
$locale_file = TEMPLATEPATH."/languages/{$locale}.php";
if ( is_readable( $locale_file ) )
{
require_once( $locale_file );
}
$sp_boxes = array( "Game Details" => array( array( "thumb", "Game image URL:" ), array( "game", "Swf URL:" ) ) );
add_action( "admin_menu", "sp_add_custom_box" );
add_action( "save_post", "sp_save_postdata", 1, 2 );
if ( !function_exists( "get_custom_field" ) )
{
function get_custom_field( $field )
{
global $post;
$custom_field = get_post_meta( $post->ID, $field, true );
echo $custom_field;
}
}
post code:
<div id="playgame">
<script type="text/javascript">
<!--
swf("<?php $values = get_post_custom_values("game"); echo $values[0]; ?>", "701", "550");//-->
</script>
</div>
By the way I tried to change dirrectory or to copy single.php to index.php but both not worked.
If I understand you right, you want the game to appear on the main page without entering a post? In that case, I think you can try using a static frontpage instead of latest posts.
You can find it on Appearance -> Customize, and then choose the frontpage to be static. That way you can have your game on the static frontpage.
Related
I develop my first plugin, which creates some pages programatically by this method:
$page_id = wp_insert_post(
array(
'comment_status' => 'close',
'ping_status' => 'close',
'post_author' => 1,
'post_title' => 'HSN Form',
'post_name' => strtolower(str_replace(' ', '-', trim('hsn-form'))),
'post_status' => 'publish',
'post_type' => 'page',
)
);
And I set template file for it:
add_filter( 'page_template', 'hsn_service_form_page_template', 10, 1 );
function hsn_service_form_page_template( $page_template ){
if ( is_page( 'hsn-form' ) ) {
$page_template = plugin_dir_path(__DIR__) . 'service-form/form-template.php';
}
return $page_template;
}
After I would like to hide it completely from wordpress dashboard, but those have to available following way:
wwww.example.com/hsn-form.
I can hide it following code from Pages menu:
add_filter( 'parse_query', 'ts_hide_pages_in_wp_admin' );
function ts_hide_pages_in_wp_admin($query) {
global $pagenow,$post_type;
$page = get_page_by_path('hsn-form');
if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
$query->query_vars['post__not_in'] = array($page->ID);
}
}
It's ok, but it's still available in Appereance->Menu, where you can create nav menus.
I searched for it, but I can't find complete solution for my problem:
My plugin has to create some pages which are available this way: www.example.com/hsn-form
I need to hide this pages completely from admin dashboard
I would like to apply templates for these pages to add some custom php code.
So If somebody should know a complete solution for it, that should be great.
Thank you in advance!
change parse_query to pre_get_posts
In order to remove a page from the admin nav menu, you can hook into the admin_menu action, then manipulate the global $submenu variable.
add_action('admin_menu', function(){
global $submenu;
array_walk($submenu, function(&$child, $parent){
if( $parent != 'edit.php' )
return;
foreach($child as $key=>$submenu){
if( $submenu[2] == 'post-new.php' ) {
unset($child[$key]);
break;
}
}
});
});
In that example, we are looking for a subpage with the slug of post-new.php
underneath the top level page with the slug edit.php. If found, it gets altogether removed from the navigation menu.
The $submenu[2] part is looking for the slug element in the array. If you want to match by the submenu name instead, you can replace it with $submenu[0].
Please Help
I want to make a search page for images stored in media gallery of wordpress. This page contains a textbox in which user will enter the number of image. The matched image should display in the different tab of browser.
I made a raw html page in wordpress where i put the which display a textbox but don't understand that where i have to write the php code to extract the images and how to show them.
Please give step by step instructions to solve the issue because i am beginner in wordpress.
You can create a custom function in functions.php for this and you can call that in your template
//In functions.php
if( ! ( function_exists( 'get_media_from_name' ) ) ) {
function get_media_from_name( $postName ) {
$args = array(
'name' => $postName,
'posts_per_page' => -1,
'post_type' => 'attachment',
);
$attachment = new WP_Query( $args );
if ( $attachment)
return $attachment;
else
return false;
}
}
//In you template where you can call that function
$get_all_matched_attachments = get_media_from_name( $postName );
if ( $get_all_matched_attachments ) {
foreach($get_all_matched_attachments as $get_all_matched_attachment){
echo '<pre>';print_r($get_all_matched_attachment);
}
}
I have created a post format of video and also created a single-video.php to display a single video post.
added following code to functions.php include single video page template.
function templateForSingleVideo( $template ) {
if ( is_single() && has_post_format() ) {
$post_format_template = locate_template( 'single-' . get_post_format() . '.php' );
if ( $post_format_template ) {
$template = $post_format_template;
}
}
return $template;
}
add_filter( 'template_include', 'templateForSingleVideo' );
it works perfectly fine. but now I want a page where the posts (post format=video) will be shown from all the categories. Just want to show all the videos..
Sorry for my bad English.
Thanks
I'm new on wordpress and i'm trying to create an archive page for multiple custom post type.
I have two custom post type, 'fair' and 'exhibition'
I currently have two archive page, with pre get post action :
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() // VERY important, targets only front end queries
&& $q->is_main_query() // VERY important, targets only main query
&& $q->is_post_type_archive( 'fair' ) // Which post type archive page to target
) {
$q->set( 'oderby', 'meta_value_num' );
$q->set( 'meta_key', '_datepicker');
$q->set('showposts', 3);
$q->set('is_post_type_archive', false);
$q->set('order', 'ASC');
// Rest of your arguments to set
}
});
both of the custom post type have the same meta box and i want to display both post type on the archive page "fair" or in a new one if necessary
i tried to add
$q->set('post_type', array('fair', 'exhibition'));
to the function.
When i do that i have my both post type but my custom archive page ("archive-fair.php") do not seems to be called
How can i perform the archive page for both post type properly with functional pagination ?
Thanks and sorry for my english, i hope it's understandable.
Edit : my archive-post.php page look like :
<?php get_header();
while ( have_posts() )
{
the_post();
$p_type = get_post_type(get_the_ID());
if ($p_type == 'fair')
$img = get_post_meta(get_the_ID(), "wp_fair_attachment", true);
else
$img = get_post_meta(get_the_ID(), "wp_exhibition_attachment", true);
?>
some html
<?php } ?>
An alternative approach is to use template_include
Try this code and let me know if it works:
add_filter( 'template_include', function( $template ){
$your_types = array( 'fair', 'exhibition' );
$post_type = get_post_type();
if ( ! in_array( $post_type, $your_types ) )
return $template;
return get_stylesheet_directory() . '/single-fair.php';
});
I have custom post type named soto_property in which I have added three wp_editor as post meta, using this code -
wp_editor( htmlspecialchars_decode($valueeee1),
'propertyEditor1',
$settings = array('textarea_name'=>'detail',
'editor_class'=>'propertyEditor')
);
wp_editor( htmlspecialchars_decode($valueeee2),
'propertyEditor2',
$settings = array('textarea_name'=>'features',
'editor_class'=>'propertyEditor')
);
wp_editor( htmlspecialchars_decode($valueeee3),
'propertyEditor3',
$settings = array('textarea_name'=>'text_to_pdf',
'editor_class'=>'propertyEditor')
);
Now I have installed qtranslate plugin to make my site Multilingual. This plugin automaticaly add Language tab in its default content editor. I want to add these languages tabs in my custom editor also, so it can save content in defined languages.
How can I do this.? Please help me.
add_filter('soto_property','qtrans_convertURL');
I guess you need to define translatable strings. Check this page in codex for more details.
Updated code should look like this:
$settings = array('textarea_name'=>__('detail', 'your-text-domain'),
'editor_class'=>'propertyEditor')
If it won't work for you, try the following trick.
Here's a code snippet from the last link:
if ( is_admin() && function_exists("qtrans_getSortedLanguages") ) {
add_action('admin_menu', 'enable_qTranslate_Meta');
}
function enable_qTranslate_Meta() {
global $qtransMETA;
$post_types = get_post_types();
/* post and page types are already processed by the plugin */
$disabled_types = array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' );
$enabled_types = array_diff( $post_types, $disabled_types );
if ( $enabled_types ) {
foreach( $enabled_types as $enabled_type ) {
add_meta_box(
'qtrans_meta_meta_box', //HTML id
__('Multilingual META', 'qtranslate-meta'), //title
array(&$qtransMETA, 'meta_box_generate'), //callback
$enabled_type, //type
'normal', //context - normal, advanced, side
'high' //priority - high, low
);
}
}
}
Solved!
I have used qranslate-x plugin which makes my custom wp_editor translatable on my custom post type page.