Midousir

Mr.Midou's life record

转载:WordPress“添加媒体”文件时只显示上传到当前文章的附件图片

WordPress“添加媒体”文件时只显示上传到当前文章的附件图片

这篇文章对于wordpress站长来说,我觉得真的很贴心,大家可以收藏一下,我也是直接转载过来,文章由:泪雪博客的博主张子凡写的。


近子凡把很大一部分精力都分散在了泪雪建站的改版和泪雪网的运营中去了,随着泪雪网的定位和内容的新增,网站也需要有很多细节的升级,而在今天就给大家分享一个 WordPress 如何在编辑文章时“添加媒体”中默认只显示上传到本文中的附件的方法。

《转载:WordPress“添加媒体”文件时只显示上传到当前文章的附件图片》

使用 WordPress 的朋友应该都清楚,特别是喜欢图文并茂的网站,肯定离不开的就是 WordPress 文章编辑页面的“添加媒体”按钮,每次点击就能弹出一个插入多媒体的界面,然后页面默认就会列举加载所有最近的媒体库上传的文件,从而文件过多过大的请求下载,就可能造成页面的卡顿或假死,同时也会造成服务器带宽资源的浪费,严重影响网站内容的编辑和效率。

那么正是根据子凡亲自遇到的这个问题,就寻找了一些方法,其中网上已经有分享相关的方法,都是从国外某问答类的站点转载过来的,从而出现的问题就只能看到上传到当前文章的附件,其它的所有多媒体选项就失效了,虽然可以解决问题,但是当我们需要查看之前或者全部附件的时候就完全无力了,所以子凡决定自己研究研究。最终代码如下:

//WordPress “添加媒体”文件时只显示上传到当前文章的附件
//add_action( 'wp_footer', 'fanly_mediapanel_lock_uploaded' );//让前台编辑器也生效
add_action( 'admin_footer-post-new.php', 'fanly_mediapanel_lock_uploaded' );
add_action( 'admin_footer-post.php', 'fanly_mediapanel_lock_uploaded' );
function fanly_mediapanel_lock_uploaded() {
	echo '<script type="text/javascript">var $i=0;jQuery(document).on("DOMNodeInserted", function(){if(jQuery("#media-attachment-filters").length>0&&$i==0){jQuery(\'select.attachment-filters [value="uploaded"]\').attr(\'selected\',true).parent().trigger(\'change\');$i++;}});</script>';
}

WordPress 的老规矩依旧将以上代码添加到当前主题的 functions.php 文件中即可。

其实就是在页面中添加了一段 js,子凡做了一个额外的 if 判断,从而完美实现效果,默认第一次点击“添加媒体”的时候默认就是显示上传到当前文章的附件了,而不是全部,大大的提高了编辑效率,当然也可以很轻松的选择显示全部媒体问题,是不是很简单呢?

除非注明,否则均为泪雪博客原创文章,转载请以链接形式标明本文地址

本文链接:https://zhangzifan.com/wordpress-media-only-uploaded.html

除非注明,否则均为Midousir原创文章,转载必须以链接形式标明本文链接

本文链接:http://www.midousir.com/2018/10/wordpress-image-page/

  1. m88gin说道:

    If you happen to be visiting another city in order to find that
    there's a good show in this city, you can not investigate different lenders for that box
    office, stand in a line and purchase the tickets. There these were, anticipating their forthcoming experience and joyously reliving the last one -- Peter, Susan, Edmund,
    and Lucy, inside guises of actors William Moseley (now a dashing 20-year-old), Anna Popplewell
    (a newly minted Oxford freshman), Skandar Keynes (with vocal octaves greater when he
    was 15), and Georgie Henley (approaching teenhood, an excellent six inches taller than we last saw her).
    With the amount of el cheapo acoustic guitars being created nowadays you
    will likely need somebody you trust that will help you choose your first guitar.

  2. M88.com说道:

    The process begins in the uncomplicated activity of the account option.
    Cherry blossom tattoos represent various things in various cultures.
    Now you've taken that all-important initial step and are looking over this report
    about online games and social networking, you're inside the unique and privideged position for being amongst a group of pioneering
    entreprenuers who may have learned concerning this and so are taking
    affirmative action.

  3. The camera may make the brightest of scenes appear to be it had been taken during an eclipse.

    These guides let you practice when you are prepared and also have the
    time to do so. Instead of enjoying karaoke
    parties, it is possible to always take the music and create your own personal
    song, by plugging it to your TV sets.

  4. The process begins from your uncomplicated activity associated with an account option. "Because you might be here reading this games report now as of this particular moment in time; that which you have is "The
    first movers advantage" by yourself to take a hold of now. The Open Video Project: This is site using a huge variety of digital video for sharing.

  5. Many of these shows are located in bigger cities like New
    York or Los Angeles, which means you arrive at travel totally free when you get in to the finals.
    You don't have to put money into the biggest or heaviest tripod web hosting use.
    You need a special connector typically called a Fire wire
    or best known as a possible IEEE 1394 high band connector.

  6. As a result of their work, Positive View's events have received coverage from the 3 major global television networks and have already been streamed for online viewing.
    " It was President Theodore Roosevelt who had given it the name of White House in 1901. The first lesson you need to learn with your online course is how to read chord charts.

  7. link ms3388说道:

    There is a rich diversity to the telltale songs which you likely will appreciate
    also to help make your life easier, and also to make it easier that will get the background music for My - Space that you want, you also
    have the ability to pick from different genres. Cherry blossom tattoos represent something more important in various cultures.
    These art reproductions of paintings printed on canvas sheets or paper and then framed
    and hung on walls.

  8. Good day I am so thrilled I found your web site, I really found you by error,
    while I was browsing on Yahoo for something else, Regardless I am here now and would just like to say kudos for a tremendous post and a
    all round thrilling blog (I also love the
    theme/design), I don't have time to look over it all at the moment but
    I have saved it and also included your RSS feeds, so when I
    have time I will be back to read much more, Please do keep up the great work.

  9. 토토说道:

    If you are an aspiring writer it is a great way to get started since it gives you publishing
    credit in addition to a . Using a host of SEO tools they are going to then recognize how well your internet site is currently doing
    and you skill to boost your web traffic and obviously your revenues.
    Website design in flash may be conveyed in vector format,
    which indicates that image quality and file size aren't based on each other.

  10. bong88说道:

    The process begins in the uncomplicated activity associated with an account option. While online machines provide the players the
    opportunity to select how much they choose to wager, these online video poker
    machine provide that same sense of strategizing and negotiations with oneself so frequently yearned for by players who miss the land-based casinos.
    The Open Video Project: This is site having a huge variety of digital video for
    sharing.

  11. m88mi说道:

    The process begins in the uncomplicated activity of your account
    option. While online machines provide players the ability to select how much they decide to wager, these online
    video poker machine provide that same feeling of strategizing and negotiations with oneself so often yearned
    for by players who miss the land-based casinos.
    With the number of el cheapo acoustic guitars being produced nowadays you will
    likely need somebody you trust to assist you choose a guitar.

  12. m888.com说道:

    There is a rich diversity to the telltale songs that you just
    will likely appreciate and also to make your life easier, also to make it
    easier to get the music activity for My - Space that you
    would like, you also have a chance to select from different genres.
    They will shun jobs its keep is not any profit to the community involved.

    The plastic's name is frequently abbreviated to CR-39, standing for Columbia Resin, which is less than 50 % the load of glass, which supplanted quartz
    inside early twentieth century.

  13. sieucacuoc.com说道:

    The process begins in the uncomplicated activity associated with an account
    option. While online machines provide players the opportunity select how much they choose to wager,
    these online video poker machine provide that same a feeling of strategizing and negotiations
    with oneself so often yearned for by players who miss the land-based casinos.
    The plastic's name is usually abbreviated to CR-39, standing for Columbia Resin,
    in fact it is less than half the body weight of glass,
    which supplanted quartz inside the early twentieth century.

  14. w88v.com说道:

    Free PC alternatives to Recycle and Phatmatik Pro:Loopdrive3 VSTABS.
    While online machines offer the players the ability to choose how much they decide to wager, these online video
    poker machine provide that same feeling of strategizing and negotiations with oneself usually yearned for by players who miss the land-based casinos.
    Now you've taken that all-important starting point and they are scanning this report about online flash games
    and social networking, you might be in the unique and
    privideged position of being amongst a group of pioneering
    entreprenuers who may have learned relating to this
    and therefore are taking affirmative action.

  15. 토토사이트说道:

    While many manufacturers possess a print catalogue you are able to browse and order from, they often also have
    a very website where they may put items on sale.
    One red light generally appears if you have a hardware problem within the
    console as well as red lights appear when there is an overheating problem.
    But you should be careful, most put banners on your site
    after having a specific amount of your time has past and
    some will want that you join and be active within their forum.

  16. 검증사이트说道:

    Especially within the wake of insufficient time and inclination to go out-of-doors, the games offer
    ideal way of action-packed entertainment within the lazy
    confines of warm and comfortable home. The Greek word that is depicted cross in numerous modern Bible translations is
    stauros. The great advantage to internet websites is you can share your photos too.

  17. 해외토토说道:

    While the ongoing financial state is getting worse as well
    as the jobless rates are increasing everyday, purchasing
    an online Internet marketing course will be the way to make money and grow out of
    your unemployment line. It's a leveraging off one another's efforts form of strategy that enables your promotions to get
    advertised virally, making your pains bigger and much more successful.
    To make this happen ensure that you setup the lowest priced front end product initially make guaranteed to sell your coaching programs at the backend.

  18. Amy说道:

    I am sure this paragraph has touched all the internet viewers,
    its really really fastidious post on building up new webpage.
    Hello, i read your blog occasionally and i own a similar one and i was just
    curious if you get a lot of spam comments?
    If so how do you stop it, any plugin or anything you can suggest?
    I get so much lately it's driving me crazy so any support is very much appreciated.
    Saved as a favorite, I really like your blog! http://Www.cspan.net/

  19. 188bet说道:

    Pretty nice post. I just stumbled upon your weblog and wished to say
    that I've truly enjoyed surfing around your blog
    posts. In any case I will be subscribing on your feed and I'm hoping you write once more very soon!

  20. Maisie说道:

    Do you have a spam issue on this site; I also am a blogger, and I was wondering your situation; we have created some
    nice practices and we are looking to trade techniques with other folks, why
    not shoot me an email if interested. http://secma-nederland.nl/?option=com_k2&view=itemlist&task=user&id=471842

发表评论

电子邮件地址不会被公开。 必填项已用*标注