플러그인 없이 두꺼운 상자에 내장된 워드프레스 사용
저는 제 테마의 워드프레스에 내장된 두꺼운 박스를 사용하려고 합니다.관리자를 통해 추가하는 모든 사진에 두꺼운 박스 기능이 자동으로 들어가도록 하려고 합니다.이것을 기능에 넣으려고 했습니다.php 그러나 작동하지 않았습니다:
function fb_add_thickbox($content){
$content = preg_replace('/<a(.*?)href="(.*?).(jpg|jpeg|png|gif|bmp|ico)"(.*?)><img/U', '<a$1href="$2.$3" $4 class="thickbox"><img', $content);
return $content;
}
add_filter('the_content', 'fb_add_thickbox', 2);
코드가 실제로 작동 중이라고 가정하면(마크업이 실제로 필터링됩니까?) thickbox가 활성화되지 않았기 때문에 실패합니다.수동으로 주입해야 합니다.
@Alexcp가 언급한 바와 같이, javascript와 css를 수동으로 등록하고 대기열에 넣어야 합니다(관리 섹션 외부).preg_replace 기능 외에 템플릿에 다음을 추가합니다.Functions.php.
// register scripts
if (! function_exists(thickbox_register){
function thickbox_register() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery','http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
wp_register_script( 'thickbox', 'path to thickbox'.thickbox.js, 'jquery');
}
}
add_action('init', 'thickbox_register');
//print the now registered scripts
if (! function_exists(thickbox_enqueue){
function thickbox_enqueue() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'thickbox' );
}
}
add_action('wp_print_scripts', 'thickbox_enqueue');
// do the same for css
if (! function_exists(thickbox_style_enqueue){
function thickbox_style_enqueue() {
wp_register_style( 'thickbox', 'path to css'.thickbox.css );
wp_enqueue_style( 'thickbox' );
}
}
add_action('wp_print_styles', 'thickbox_style_enqueue');
경로는 여러 가지 방법으로 얻을 수 있지만 다음과 같은 것을 얻을 수 있습니다.bloginfo('url');당신을 시작하게 해줘야 합니다.
여전히 문제가 있는 경우 FireBug 등을 사용하여 두꺼운 상자가 DOM의 jquery 개체에 제대로 등록되고 있는지 확인합니다.
도움이 되기를 바랍니다.
이거 나한테 잘 맞았거든요.
<?php add_thickbox(); ?>
<div id="my-content-id" style="display:none;">
<p>
This is my hidden content! It will appear in ThickBox when the link is clicked.
</p>
</div>
<a href="#TB_inline?width=600&height=550&inlineId=my-content-id"
class="thickbox">View my inline content!</a>
이것을 당신의 기능에 추가합니다.당신의 테마에 있는 php 파일:
<?php
// Adds thickbox to all images with a link inside of $content.
// Uses the title attribute in the Media Library.
add_filter('the_content', 'brentini_addthickboxclass');
function brentini_addthickboxclass($content) {
add_thickbox();
$pattern[0] = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement[0] = '<a$1href=$2$3.$4$5 class="thickbox">';
$pattern[1] = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?)(>)(.*?) title=('|\")(.*?)('|\")(.*?)(<\/a>)/i";
$replacement[1] = '$1$2$3$4$5$6 title=$9$10$11$7$8 title=$9$10$11$12$13';
$pattern[2] = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?) title=([^\>]*?) title=([^\>]*?)(>)(.*?)(<\/a>)/i";
$replacement[2] = '$1$2$3$4$5$6 title=$7$9$10$11';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
이렇게 하면 흠잡을 데 없이 효과가 있습니다.다른 사람들이 언급한 모든 통화 내용을 추가할 필요는 없습니다.워드프레스에는 백엔드에 사용할 수 있는 jquery와 thick box가 기본적으로 포함되어 있기 때문에 그것은 전혀 필요하지 않습니다.따라서 테마에서 thickbox()를 호출하는 데 필요한 것은 add_thickbox()뿐입니다.스크립트의 나머지 부분은 $content 내부의 이미지에 class=" thickbox"를 추가하고 WordPress Media Library의 제목 속성을 사용하기만 하면 됩니다.
탐색 기능이 있는 갤러리를 위한 Thickbox 지원 기능이 추가된 스크립트에 관심이 있다면 페이스트빈에서 확인하십시오.
탐색을 포함하지 않는 보다 단순화된 버전의 경우, 페이스트빈에 있는 이 파일은 jquery를 사용하여 두꺼운 상자 클래스를 갤러리에 추가합니다.
쉬운 방법으로, 워드프레스에는 이미thickbox.js스크립트 폴더에 있습니다.
그러니까 그냥 열어요.wp-include/script-loader.php
선을 보다function print_head_scripts(),
더하다$wp_scripts->do_items( 'thickbox' );끝나고$wp_scripts->do_items( 'l10n' );
그런 다음 페이지를 새로 고치면 다음을 볼 수 있습니다.thickbox.js이미 당신의 것에 포함시켜 놓았습니다.header part, 그 다음에 추가만 합니다.class="thickbox"당신의<a> tag, 두꺼운 상자를 완벽하게 부를 수 있습니다.
언급URL : https://stackoverflow.com/questions/6631447/using-wordpress-built-in-thickbox-without-plugin
'programing' 카테고리의 다른 글
| Python Process Pool non-daemonic? (0) | 2023.10.17 |
|---|---|
| 깃 푸쉬 오리진 헤드는 무엇을 의미합니까? (0) | 2023.10.17 |
| PayPal IPN 응답에서 Woocommerce 기능은 무엇입니까? (0) | 2023.10.17 |
| 테마 기능에서 도우미 기능을 정의하고 사용하는 방법.php? (0) | 2023.10.17 |
| 여러 개의 빈 열을 팬더 DataFrame에 추가 (0) | 2023.10.17 |