doufan6544 2015-06-24 19:17
浏览 61
已采纳

Wordpress - 小工具参数

I'm creating my own plugin and widget to display my latest work on my portfolio website, except I'm having some issues with the final part - displaying my data.

I've created a plugin which allows me to insert new data to my database - this holds information about a new project I've finished (Title, subtitle, href and src).

I can echo out all of this data just fine.

The next thing I did was to create a widget which allows me to display all of these bits of data, by calling it as follows:

the_widget( 'soc_latestwork','title=$data->Title.&subtitle=$data->SubTitle&image_src=$data->ImageSrc&image_url=$data->ImageUrl', array('before_widget' => '', 'after_widget' => ''));

And this displays my widget just fine... Expect the issue have is that my data is stored inside an array, which I can access by doing this

$data->Title

etc.

Now, how on earth am I meant to put this data in my widget? Whatever I put inside of it just gets echo'd out as plain text.

Here is my widget code which shows this data:

function widget($args, $instance)
    {

        extract($args);

        echo $before_widget;

        ?>

<div class="col-lg-3 col-sm-3 latest-work-box" data-scrollreveal="enter left after 0.15s over 1s">

            <!-- Image box -->

            <div class="latest-work-box-wrap">

                <a href="<?php echo $instance['image_src'] ?>" >
                    <img src="<?php echo $instance['image_url'] ?>" />
                </a>

                <div class="latest-work-box-wrap-bottom">

                <h1> <?php echo $instance['title'] ?> </h1>

                <h2> <?php echo $instance['subtitle'] ?> </h2>

                </div>

            </div>

        </div>

        <?php

        echo $after_widget;

    }
  • 写回答

1条回答 默认 最新

  • douzhixun8393 2015-06-25 16:15
    关注

    You're currently passing in an array of strings such as "$data->Title" when you should be passing the data contained within $data->Title.

    Change your widget call to this:

    the_widget( 'soc_latestwork','title='.$data->Title.'&subtitle='.$data->SubTitle.'&image_src='.$data->ImageSrc.'&image_url='.$data->ImageUrl, array('before_widget' => '', 'after_widget' => ''));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b