هذه الإضافة لم يتم تحديثها وتجربتها لأكثر من 3 إصدارات ووردبريس رئيسية. قد لا تكون خاضعة للصيانة أو تقدم الدعم والمساعدة بالوقت الحالي وقد تكون بها مشاكل في التوافق عند إستخدامها مع إصدارات حديثة من ووردبريس.

WordPress Conditional Content

الوصف

How to use

You can place conditional content between if shortcodes, and use its attributes to define conditions. The content between the shortcodes will only be displayed if all defined conditions are met.

Defining conditions

Conditions are defined by setting the attributes of the shortcode in the following format:

[if <type>=<condition>]
 Conditional content
[/if]

A basic example:

[if qs="product-type:shoes"]
 Thank you for buying shoes
[/if]

The text in this example will only be displayed if the current URL has a GET paramater of “product-type” with the value “shoes”.

Available condition types are:

  • qs – Match on the key/value pair of the defined query string/GET parameter. Query string conditions are formatted like this:

    [if qs="<qskey>:<qsvalue>"] … [/if]
    
    qskey is the name of the query string variable and `qsvalue` the value to test for. For example, the condition `qs="product-type:2"` will match `?product-type=2`.
    
  • referrer – To check on the current referrer. The condition will be true if HTTP_REFERER contains <value>. The match doesn’t need to be exact, so if a user arrives from google and <value> is set to “google.com” the condition will be true.

  • role – Matches the current user’s role. The match needs to be exact so “admin” will not match “administrator”. Use role with and empty value if you want to match users that are not logged in.

Examples

Display content based on query string:

[if qs=”utm_source:partner-site”]
This content is only displayed if the current URL contains a GET paramater ‘utm_source’ with value ‘partner-site’
[/if]

Display content based on referrer:

[if referrer="www.google.com"]
 This content is only displayed if the referring URL contains 'www.google.com'
[/if]

Display content based on user role:

[if role="editor"]
 This content is only displayed if the user is logged in with the role 'editor'
[/if]

Setting multiple conditions and combining condition types:

[if referrer="www.example.com" qs="utm_source:partner-site"]
 This content is displayed to users coming from example.com who clicked on a link originating from our RSS feed.
[/if]

Matching with `exact` or `contain`

By default query string conditions are matched on the exact value as defined in the shortcode. For looser ‘wildcard’ matching you can add a match attribute with the value contain:

[if qs="product-type:cashmere-" match="contain"]
 Good choice! Cashmere is a wonderful fabric.
[/if]

This will match both ?product-type=cashmere-sweater and ?product-type=cashmere-coat

Matching on multiple values

You can have a condition match on multiple values by using the semicolon as a seperator when defining allowed values. Example:

[if qs="product-type:shoes;coat"]
  This text is displayed for people who bought either a nice pair of shoes or a great fashionable coat.
[/if]

Nesting `if` statements

You can nest statements but you have to use iteration. This has to do with the limitations of the built-in shortcode API.

[if qs="tonight:the-night"]

  Tonight's the night.

  [if2 qs="future:beautiful"]

    We create our own destiny every day we live.

  [/if2]

  [if2 qs="future:platic"]

    I see sheets of plastic in your future.

  [/if2]

[/if]

You can nest up to if4 (4 levels).

لقطات الشاشة

  • What if statements look like in your content editor.

التنصيب

  1. Upload the ‘wp-conditional-content’ folder to your plugins directory
  2. Activate the plugin through the ‘Plugins’ menu in your WordPress admin
  3. You can now use the [if] shortcode in your post content. Read the documentation for details.

الأسئلة المتكررّة

Can I use `else` statements?

Not yet, but it’s on the to-do list

I have a request for a certain condition I want to be able to check.

Great, feel free to send me your suggestion through Twitter: @bvandreunen

المراجعات

25 يونيو، 2018
haven’t see that Kinda plugin at org. Easy to use and handy Plugin. You should keep update this. Thanks 🙂
3 سبتمبر، 2016
heya, I really liked your plugin. I think you should upgrade it to the latest version of WordPress. and keep updating. It is a nice plugin. Cheers!
إقرأ جميع المراجعات 5

المساهمون والمطوّرون

“WordPress Conditional Content” هو برنامج مفتوح المصدر. وقد ساهم هؤلاء الأشخاص بالأسفل في هذه الإضافة.

المساهمون

ترجمة ”WordPress Conditional Content“ إلى لغتك.

مُهتم بالتطوير؟

تصفّح الشفرة، تحقق من مستودع SVN، أو الاشتراك في سجل التطوير بواسطة RSS.

سجل التغييرات

  • 0.1 First release