<Object Data=...></Object>保存帖子后的更改

时间:2013-02-12 作者:tazboy

我正在尝试使用下面的代码嵌入一个交互式图形,效果很好:

<object data="https://www.desmos.com/calculator/wr4nht4qbp" width="800" height="600"></object>
当我保存帖子并查看它时,它看起来很好。当我从Text 选项卡到Visual 选项卡。一旦我这样做,它就会从上面的代码变为下面的shockwave flash代码:

<object width="800" height="600" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
<param name="src" value="https://www.desmos.com/calculator/oobmwtyhdx" />
<embed width="800" height="600" type="application/x-shockwave-flash" src="https://www.desmos.com/calculator/oobmwtyhdx" /></object>
有没有办法阻止这种情况发生?或者是否有其他方法嵌入此图形以保持其交互?

1 个回复
SO网友:Joseph Leedy

我会用shortcode 我自己在你的functions.php:

function wpa_85620_calculator_shortcode( $atts ) {
    extract( shortcode_atts( array(
        \'key\' => \'wr4nht4qbp\',
        \'width\' => 800,
        \'height\' => 800
    ), $atts ) );

    return sprintf( \'<object data="https://www.desmos.com/calculator/%s" width="%d" height="%d"></object>\', $key, $width, $height );
}
add_shortcode( \'calculator\', \'wpa_85620_calculator_shortcode\' );
在您的帖子/页面中:

[calculator] or [calculator width="400" height="200"]
作为插件(另存为calc.php 在您的plugins 文件夹):

<?php
/*
Plugin Name: Desmos Calculator
Plugin URI: http://wordpress.stackexchange.com/questions/85620/object-data-object-changes-after-i-save-a-post/85669#85669
Description: Desmos calculator shortcode
Version: 0.1
Author: Joseph Leedy
Author Email: [email protected]
License:

  Copyright 2013 Joseph Leedy ([email protected])

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

function wpa_85620_calculator_shortcode( $atts ) {
    extract( shortcode_atts( array(
        \'key\' => \'wr4nht4qbp\',
        \'width\' => 800,
        \'height\' => 800
    ), $atts ) );

    return sprintf( \'<object data="https://www.desmos.com/calculator/%s" width="%d" height="%d"></object>\', $key, $width, $height );
}
add_shortcode( \'calculator\', \'wpa_85620_calculator_shortcode\' );

结束

相关推荐

Pagination for two loops

我知道之前已经讨论过这个问题,但我似乎无法将它与其他主题中发布的任何解决方案配合使用。如何对这样的循环进行分页: <div id=\"first-loop-container\"> <?php $my_query = new WP_Query(\'showposts=5\'); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(