正在尝试使Fit Text在WordPress中工作

时间:2012-10-24 作者:Anders Kitson

我的模板页面中有以下代码,我在主题中注册了jquery和fittextfunctions.php. 当我设置它们时,它们当前显示在页脚中。我可以在页眉或页脚中设置它们,但fittext在我放置它的任何地方都不起作用。当我缩小屏幕尺寸时,字体应该会缩小,但事实并非如此。我不知道为什么会这样。

我已经建立了一个非常粗略的网站版本,它基本上只是显示了fittext不起作用,你可以查看它here 用户名:anders,密码:reading61

<?php
/*
Template Name:Tech Basics
*/
?>
<?php get_header( \'tech\' ); ?>

<div id="quote">
    <h1 id="fittext3">Sending you the techie! son you never had.</h1>
</div>
<script type="text/javascript">
        $("#fittext3").fitText();
    </script>
<div class="row mainContent">
    <div class="twelve columns">
        <?php 
        $page_id = 10; // 123 should be replaced with a specific Page\'s id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.

        $page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.

        echo apply_filters(\'the_content\', $page_data->post_content); // echo the content and retain Wordpress filters such as paragraph tags. Origin from: http://wordpress.org/support/topic/get_pagepost-and-no-paragraphs-problem
?>
    </div>
</div><!--row ends-->
<?php get_footer(); ?>

This seems to get it working however I know it isn\'t a proper technique, for some reason fittext wants the js right in the middle of the page can any one help with this.

<?php
/*
Template Name:Tech Basics
*/
?>
<?php get_header( \'tech\' ); ?>

<div id="quote">
    <h1 id="fittext3">Sending you the techie! son you never had.</h1>
</div>
<script type="text/javascript">
        $("#fittext3").fitText();
    </script>
      <h2 id="fittext1">Welcome to Foundation</h2>

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script src="http://localhost:8888/austin.kitson.orgWP/wp-content/themes/git.austin.kitson.org/js/jquery.fittext.js"></script>
    <script type="text/javascript">
        $("#fittext1").fitText();
        $("#fittext2").fitText(1.2);
        $("#fittext3").fitText(1.1, { minFontSize: 50, maxFontSize: \'75px\' });
    </script>
<div class="row mainContent">
    <div class="twelve columns">
        <?php 
        $page_id = 10; // 123 should be replaced with a specific Page\'s id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be         embedded in the query string of the URL, e.g. page.php?action=edit&post=123.

        $page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. By default, this will return an object.

        echo apply_filters(\'the_content\', $page_data->post_content); // echo the content and retain Wordpress filters such as paragraph tags. Origin from: http://wordpress.org/support/topic/get_pagepost-and-no-paragraphs-problem
?>
    </div>
</div><!--row ends-->
<?php get_footer(); ?>

1 个回复
最合适的回答,由SO网友:Anders Kitson 整理而成

我终于明白了,由于某种原因,在脚本中使用$根本不起作用,所以我不得不像这样使用jQuery

<script type="text/javascript">
     jQuery(document).ready(function() {

        jQuery("#fittext3").fitText(1.8, { minFontSize: \'12px\', maxFontSize: \'75px\' });
         });
    </script>

结束

相关推荐

WordPress/jQuery砖石画廊的各种缩略图大小

有人能帮我在Wordpress中使用jquery砌体创建一个缩略图库吗this?我不知道最好的方法是什么。尤其是不同的缩略图大小。何时以及如何分配?我得到的部分是我设置了一些不同的缩略图大小,但我如何决定加载哪个大小?由于该页面总是以相同的方式加载,因此它似乎不是随机的。砌石剧本能自己解决这个问题吗?非常感谢你的帮助!