[wp-hackers] map file path to url in PHP/WordPress
肖晗
xiaohan2012 at gmail.com
Sat Oct 22 02:27:18 UTC 2011
I inserted the die() in the VERY front.
It look fine to me as well.
Thanks anyway. :-)
在 2011年10月22日 上午10:24,Dion Hulse (dd32) <wordpress at dd32.id.au>写道:
> If you inserted the die() within the if(file_exists() check, that'll be
> why,
> as that filepath is wrong, WP_PLUGIN_DIR refers to the plugins folder, not
> the plugins folder.
>
> The better way would be to write that as
> $screen_filepath = dirname(__FILE__) . '/css/screen.css';
> if you really want to check for it's existence first.
>
> other than that, it looks fine to me from what I know of it.
>
> 2011/10/22 肖晗 <xiaohan2012 at gmail.com>
>
> > Thanks very much, Dion. This is what I want.
> >
> > But now I have problem with registering the style sheet.
> > I did as the Wordpress function references suggest.
> > <code>
> >
> > *add_action*
> > ('wp_print_styles','add_pll_style_sheet');
> >
> > function *add_pll_style_sheet*(){
> > $screen_filepath = WP_PLUGIN_DIR.'/'.'css/screen.css';
> > if(file_exists($screen_filepath)){
> >
> > wp_register_style("blueprint_screen",plugins_url('css/screen.css',
> > __FILE__));
> > wp_enqueue_style('blueprint_screen');
> > }
> > }
> >
> > </code>
> > The *add_pll_style_sheet*() won't execute at all! (I tested it adding a
> *
> > die*() in the front, but nothing happens)
> > And I don't think the action *wp_print_styles *is wrong, because I did
> as
> > the wordpress reference suggests.
> >
> > And the context is correct, I think.Because other functions(hooks) are
> > executed smoothly, except this one.
> >
> > Any idea?
> >
> > 2011/10/22 Dion Hulse (dd32) <wordpress at dd32.id.au>
> >
> > > If you're referring to the file from within a plugin, you'd use
> something
> > > such as:
> > > echo plugins_url('mystyle.css', __FILE__); (The __FILE__ part makes it
> > > refer
> > > to mystyle.css relative to the current file)
> > >
> > > If you were refering to a themes file, you'd use something such as:
> > > echo get_template_directory_uri() . '/some-style-file.css';
> > >
> > > On 22 October 2011 12:31, 肖晗 <xiaohan2012 at gmail.com> wrote:
> > >
> > > > Hi guys,
> > > >
> > > > I do not know how to map file path to url in PHP/WordPress.
> > > >
> > > > Suppose my css sheet is in path
> > > >
> > > > /var/www/wordpress/wp-content/plugins/my-plugin/mystyle.css.
> > > >
> > > > And suppose my domain is domain.com.
> > > >
> > > > How can I map the path
> > > >
> > > > /var/www/wordpress/wp-content/plugins/my-plugin/mystyle.css
> > > >
> > > > to
> > > >
> > > > http://domain.com/wordpress/wp-content/plugins/my-plugin/mystyle.css
> > > >
> > > > Any useful functions and Wordpress API will be appreciated
> > > > _______________________________________________
> > > > wp-hackers mailing list
> > > > wp-hackers at lists.automattic.com
> > > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > > >
> > > _______________________________________________
> > > wp-hackers mailing list
> > > wp-hackers at lists.automattic.com
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list