- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的每篇帖子中,我都在其中放置了一个商店帖子小部件。下面提供了 post widget 插件 php 的商店。有了这个插件,你只需在你的帖子 html 中放置一个简短的代码。 (商店小部件网站在生成小部件后为您提供此代码)
您可以放入帖子 html 中的示例短代码 - [show_shopthepost_widget id="2371382"]
小部件的外观 -
我想要发生的是让商店的帖子小部件出现在我的首页上的帖子标题和摘录下方。我尝试通过添加 echo do_shortcode() 来做到这一点。但这没有用。有人有解决办法吗?我很困惑,希望得到任何帮助。
*我将为每个帖子使用不同的小部件 ID,因为每个帖子都有不同的商店帖子小部件。
这里是插件代码(我用于小部件的网站有许多其他购物小部件,例如精品店和产品目录,这就是为什么除了商店帖子小部件之外,您还会看到一些其他小部件,这就是我的内容)我正在工作)
<?php
/*
Plugin Name: rewardStyle Widget
Plugin URI: http://www.rewardstyle.com
Description: The rewardStyle plugin allows bloggers to use rewardStyle widgets on their WordPress blog
Author: rewardStyle
Author URI: http://www.rewardstyle.com
Version: 1.53
*/
require 'plugin-updates/plugin-update-checker.php';
$ExampleUpdateChecker = new PluginUpdateChecker_1_5(
'http://www.rewardstyle.com/assets/info.json',
__FILE__,
'rewardstyle-widgets',
1
);
/**
* Add these to the KSES 'Allowed Post Tags' global
* var. Keeps these tags from being removed in the
* save/update process.
*/
$GLOBALS['allowedposttags']['iframe'] = array(
'id' => TRUE,
'class' => TRUE,
'title' => TRUE,
'style' => TRUE,
'align' => TRUE,
'frameborder' => TRUE,
'height' => TRUE,
'longdesc' => TRUE,
'marginheight' => TRUE,
'marginwidth' => TRUE,
'name' => TRUE,
'scrolling' => TRUE,
'src' => TRUE,
'width' => TRUE
);
$GLOBALS['allowedposttags']['script'] = array(
'id' => TRUE,
'class' => TRUE,
'src' => TRUE,
'type' => TRUE,
'name' => TRUE
);
/**
* Add these to the Tiny MCE whitelist of acceptable Tags.
* This keeps the values available when loading the page,
* and when switching from Visual/Text Tabs
*/
function unfilter_iframe($initArray) {
if (isset($initArray['extended_valid_elements'])) {
$initArray['extended_valid_elements'] .= ",+iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]";
}
else {
$initArray['extended_valid_elements'] = "+iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]";
}
return $initArray;
}
function unfilter_script($initArray) {
if (isset($initArray['extended_valid_elements'])) {
$initArray['extended_valid_elements'] .= ",+script[id|class|src|type|name]";
}
else {
$initArray['extended_valid_elements'] = "+script[id|class|src|type|name]";
}
return $initArray;
}
add_filter('tiny_mce_before_init', 'unfilter_iframe');
add_filter('tiny_mce_before_init', 'unfilter_script');
// Add shortcode support to completely bypass the iframe filter
add_shortcode( 'show_rs_widget', 'rs_show_widget');
function rs_show_widget($atts, $content = null) {
extract(shortcode_atts(array(
'wid' => '',
'blog' => '',
'product_ids' => '',
'rows' => '',
'cols' => '',
'brand' => '',
'price' => '',
'hover' => ''
), $atts));
$h = $rows * 120;
$w = ($cols * 110) + 50;
$magic_num = 0;
$how_tall = '120';
$prod_box = 'show';
if ($brand == 1) {
$magic_num++;
}
if ($price == 1) {
$magic_num++;
}
if ($hover == 1) {
$magic_num = 0;
$prod_box = 'hover-info';
}
if ($magic_num == 1) {
$how_tall = '162';
} else if ($magic_num == 2) {
$how_tall = '195';
}
$out = "<div style='width: ".$w."px; height: ".$how_tall."px; margin: 0px auto; background:white;'>
<iframe frameborder='0' width='".$w."px' height='".$how_tall."px' scrolling='no' src='http://currentlyobsessed.me/api/v1/get_widget?wid=".$wid."&blog=".$blog."&product_ids=".$product_ids."&rows=".$rows."&cols=".$cols."&brand=".$brand."&price=".$price."&hover=".$hover."'></iframe>
</div>";
return $out;
}
function ms_show_widget($atts) {
extract(shortcode_atts(array(
'id' => '0',
'image_id' => '0',
'width' => '0',
'height' => '0',
'adblock' => 'Disable your ad blocking software to view this content.',
'enableJs' => 'JavaScript is currently disabled in this browser. Reactivate it to view this content.'
), $atts));
$out = '<div class="moneyspot-widget" data-widget-id="'.$id.'">
<script type="text/javascript" language="javascript">
!function(d,s,id){
var e, p = /^http:/.test(d.location) ? \'http\' : \'https\';
if(!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + \'://widgets.rewardstyle.com/js/widget.js\';
d.body.appendChild(e);
}
if(typeof(window.__moneyspot) === \'object\') {
if(document.readyState === \'complete\') {
window.__moneyspot.init();
}
}
}(document, \'script\', \'moneyspot-script\');
</script>
<div class="rs-adblock">
<img src="//images.rewardstyle.com/img?v=2.11&ms='.$id.'&aspect" onerror="this.parentNode.innerHTML=\'Turn off your ad blocker to view content\'" />
<noscript>'.$enableJs.'</noscript>
</div>
</div>';
return $out;
}
add_shortcode('show_ms_widget', 'ms_show_widget');
function ltk_show_widget($atts) {
extract(shortcode_atts(array(
'user_id' => '0',
'rows' => '1',
'cols' => '6',
'show_frame' => 'true',
'padding' => '0'
), $atts));
$out = '<div class="ltkwidget-widget" data-rows="'.$rows.'" data-cols="'.$cols.'" data-show-frame="'.$show_frame.'" data-user-id="'.$user_id.'" data-padding="'.$padding.'">
<script type="text/javascript" language="javascript">
!function(d,s,id){
var e, p = /^http:/.test(d.location) ? \'http\' : \'https\';
if(!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + \'://widgets.rewardstyle.com/js/ltkwidget.js\';
d.body.appendChild(e);
}
}(document, \'script\', \'ltkwidget-script\');
if(typeof(window.__ltkwidget) === \'object\'){
if (document.readyState === \'complete\') {
__ltkwidget.init();
}
}
</script>
<div class="rs-adblock">
<img src="//assets.rewardstyle.com/images/search/350.gif" onerror="this.parentNode.innerHTML=\''.$adblock.'\'" />
<noscript>'.$enableJs.'</noscript>
</div>
</div>';
return $out;
}
add_shortcode('show_ltk_widget', 'ltk_show_widget');
function ltk_widget_version_two($atts) {
extract(shortcode_atts(array(
'app_id' => '0',
'user_id' => '0',
'rows' => '1',
'cols' => '6',
'show_frame' => 'true',
'padding' => '0'
), $atts));
$out = '<div id="ltkwidget-version-two'.$app_id.'" data-appid="'.$app_id.'" class="ltkwidget-version-two">
<script>var rsLTKLoadApp="0",rsLTKPassedAppID="'.$app_id.'";</script>
<script type="text/javascript" src="//widgets-static.rewardstyle.com/widgets2_0/client/pub/ltkwidget/ltkwidget.js"></script>
<div widget-dashboard-settings="" data-appid="'.$app_id.'" data-userid="'.$user_id.'" data-rows="'.$rows.'" data-cols="'.$cols.'" data-showframe="'.$show_frame.'" data-padding="'.$padding.'">
<div class="rs-ltkwidget-container">
<div ui-view=""></div>
</div>
</div>
</div>';
return $out;
}
add_shortcode('show_ltk_widget_version_two', 'ltk_widget_version_two');
function lookbook_show_widget($atts) {
extract(shortcode_atts(array(
'id' => '0',
'adblock' => 'Turn off your ad blocker to view content',
'enableJs' => 'Turn on your JavaScript to view content'
), $atts));
$out = '<div class="lookbook-widget" data-widget-id="'.$id.'">
<script type="text/javascript" language="javascript">
!function(d,s,id){
var e, p = /^http:/.test(d.location) ? \'http\' : \'https\';
if(!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + \'://widgets.rewardstyle.com/js/lookbook.js\';
d.body.appendChild(e);
}
if(typeof(window.__lookbook) === \'object\') if(d.readyState === \'complete\') {
window.__lookbook.init();
}
}(document, \'script\', \'lookbook-script\');
</script>
<div class="rs-adblock">
<img src="//assets.rewardstyle.com/images/search/350.gif" style="width:15px;height:15px;" onerror="this.parentNode.innerHTML=\''.$adblock.'\'" />
<noscript>'.$enableJs.'</noscript>
</div>
</div>';
return $out;
}
add_shortcode('show_lookbook_widget', 'lookbook_show_widget');
function shopthepost_show_widget($atts) {
extract(shortcode_atts(array(
'id' => '0',
'adblock' => 'Turn off your ad blocker to view content',
'enableJs' => 'Turn on your JavaScript to view content'
), $atts));
$out = '<div class="shopthepost-widget" data-widget-id="'.$id.'">
<script type="text/javascript" language="javascript">
!function(d,s,id){
var e, p = /^http:/.test(d.location) ? \'http\' : \'https\';
if(!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + \'://widgets.rewardstyle.com/js/shopthepost.js\';
d.body.appendChild(e);
}
if(typeof window.__stp === \'object\') if(d.readyState === \'complete\') {
window.__stp.init();
}
}(document, \'script\', \'shopthepost-script\');
</script>
<div class="rs-adblock">
<img src="//assets.rewardstyle.com/images/search/350.gif" style="width:15px;height:15px;" onerror="this.parentNode.innerHTML=\''.$adblock.'\'" />
<noscript>'.$enableJs.'</noscript>
</div>
</div>';
return $out;
}
add_shortcode('show_shopthepost_widget', 'shopthepost_show_widget');
function boutique_show_widget($atts) {
extract(shortcode_atts(array(
'id' => '0',
'adblock' => 'Turn off your ad blocker to view content',
'enableJs' => 'Turn on your JavaScript to view content'
), $atts));
$out = '<div class="boutique-widget" data-widget-id="'.$id.'">
<script type="text/javascript" language="javascript">
!function(d,s,id){
var e, p = /^http:/.test(d.location) ? \'http\' : \'https\';
if(!d.getElementById(id)) {
e = d.createElement(s);
e.id = id;
e.src = p + \'://widgets.rewardstyle.com/js/boutique.js\';
d.body.appendChild(e);
}
if(typeof window.__boutique === \'object\') if(d.readyState === \'complete\') {
window.__boutique.init();
}
}(document, \'script\', \'boutique-script\');
</script>
<div class="rs-adblock">
<img src="//assets.rewardstyle.com/images/search/350.gif" style="width:15px;height:15px;" onerror="this.parentNode.innerHTML=\''.$adblock.'\'" />
<noscript>'.$enableJs.'</noscript>
</div>
</div>';
return $out;
}
add_shortcode('show_boutique_widget', 'boutique_show_widget');
add_filter('widget_text', 'do_shortcode');
add_filter('the_excerpt', 'do_shortcode');
?>
然后是我的 front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
<?php echo do_shortcode("show_shopthepost_widget"); ?>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
<?php echo do_shortcode("show_shopthepost_widget"); ?>
</article>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
更新了 front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
<?php echo do_shortcode("show_shopthepost_widget"); ?>
<?php if (shortcode_exists('show_shopthepost_widget')) {
// Get the value of the custom field defined in the editor
$widgetId = get_post_meta(get_the_ID(), 'shortcode_id', true);
// Check if a value is set
if (!empty($widgetId)) {
$shortcode = '[show_shopthepost_widget id="'.$widgetId.'"]';
} else {
// or use a default widget
$shortcode = '[show_shopthepost_widget id="12345_some_id"]';
}
do_shortcode($shortcode);
} ?>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
<?php if (shortcode_exists('show_shopthepost_widget')) {
// Get the value of the custom field defined in the editor
$widgetId = get_post_meta(get_the_ID(), 'shortcode_id', true);
// Check if a value is set
if (!empty($widgetId)) {
$shortcode = '[show_shopthepost_widget id="'.$widgetId.'"]';
} else {
// or use a default widget
$shortcode = '[show_shopthepost_widget id="12345_some_id"]';
}
do_shortcode($shortcode);
} ?>
</article>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
最佳答案
实际上,do_shortcode()正是您所需要的,只是您需要按原样输入整个短代码,而不对其进行更改(即删除 []
)
这应该可以很好地显示上面的小部件:
echo do_shortcode('[show_shopthepost_widget id="2371382"]');
此外,我建议将其包装在 shortcode_exists() 中检查,否则如果插件因任何原因被禁用或不可用,它会在页面上吐出短代码。 请注意,此函数需要传递不带 []
的短代码。
if (shortcode_exists('show_shopthepost_widget')) {
echo do_shortcode('[show_shopthepost_widget id="2371382"]');
}
Wordpress Stack Exchange如果您一直在使用 WP,网站可能会为您提供更多答案。希望这有帮助!
编辑
如果您需要在每个页面上显示不同的短代码,您可以修改上述代码以使用自定义字段来显示与页面关联的任何小部件,或者如果您未设置任何小部件,则显示默认小部件。
为此,您需要在网站的 wp-admin
和 add a custom field 中编辑页面。向他们提供您想要在页面上显示的小部件的 ID,并将其命名为诸如 shortcode_id
之类的合理名称。
您需要修改逻辑以使用与当前页面关联的 shortcode_id
键获取帖子元,并创建要相应显示的短代码。此外,您还可以设置一个默认小部件,如果您没有为页面设置任何小部件,则会显示该默认小部件。
if (shortcode_exists('show_shopthepost_widget')) {
// Get the value of the custom field defined in the editor
$widgetId = get_post_meta(get_the_ID(), 'shortcode_id', true);
// Check if a value is set
if (!empty($widgetId)) {
$shortcode = '[show_shopthepost_widget id="'.$widgetId.'"]';
} else {
// or use a default widget
$shortcode = '[show_shopthepost_widget id="12345_some_id"]';
}
echo do_shortcode($shortcode);
}
关于javascript - 在首页上显示帖子中的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41898308/
我想向一些用户公开一个 Web 部件,但不是所有用户。如何在“添加 Web 部件”弹出窗口中显示或隐藏 Web 部件?我想通过代码来做到这一点,我希望使用 SharePoint 角色来实现这一点。 最
我无法创建两个以上的 StatusBar 部分: HWND hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, "", WS_CHILD | WS_VISI
使用 SharePoint 2007,如何在编辑页面模式下允许将 CEWP 添加到“添加 Web 部件”对话框的选择菜单?目前,我只能添加公告、日历、链接、共享文档、任务,但我无法添加 CEWP。我可
哪个 Web 部件以及如何配置它以查看来自不同网站集的列表? 请注意,我不想查看页面,而是查看列表。例如,在单独的网站集下查看来自不同团队网站的公告。 预先感谢您的帮助。 最佳答案 Data Form
以下是我在 FeatureDeactivation 事件处理程序中添加的代码片段。我无法获得删除 System.Web.UI.WebControls.WebParts 类型的 webpart 的解决方
我一直在尝试跟踪来自以下方面的信息: Long URL clipped to stop breaking the page 和 http://msdn.microsoft.com/en-us/libr
我想创建一个自定义 Web 部件,它具有 1 个以上的筛选器 Web 部件,并且可以在运行时/设计时连接到报表查看器 Web 部件(集成模式)。 我为此搜索了很多,但找不到一种方法来让单个 Web 部
我正在尝试创建一个 Web 部件,使用户无需离开 AllItems.aspx 页面即可编辑项目。 Web 部件应具有与 EditForm.aspx 页面类似的功能。 我已经使用 ConnectionC
这些年发布的许多应用程序都有新的 GUI 部件。iTunes 或 Twitter.app 中垂直布局的最小、最大和关闭按钮(但最新的具有默认布局),Safari 和终端中的选项卡控件,GarageBa
在具有数据库依赖性的 WSS3 或 MOSS2007 中部署 Web 部件的最佳方法是什么? .wsp 是否应该包含创建数据库的代码,我应该将 .wsp 封装在另一个处理数据库创建的安装程序中,还是应
我在我们位于 http://sharepoint:12345 的 moss 服务器上创建了一个新的共享点站点并毫无问题地向其添加了 CQWP。 我有一个指向同一台服务器的域名。所以我指向了http:/
在官方 Office 2007 站点中有许多对筛选器 Web 部件的引用。当我尝试添加其中之一时,我的 Sharepoint 中的 Web 部件列表没有显示任何筛选器 Web 部件。 如果有人遇到相同
我被要求在 Sharepoint 中创建一个 Web 部件,列出用户在网站集中访问的最后 10 个文档。 我的客户想要一种快速的方式让用户访问文档,这样他们就不必翻遍文件夹结构来查找文档,因为大多数时
我需要使用 C# 以编程方式将 SharePoint Web 部件“站点用户”添加到页面。 我知道如何添加 Web 部件,但如何从 Share Point 获取“站点用户”Web 部件?我不知道如何实
我正在使用 MEF 在我的应用程序中加载插件。一切正常,但我希望在将新部件放入我的应用程序文件夹时发现它们。这可能吗? DirectoryCatalog 有一个 Changed 事件,但我不确定它是如
我有一个 Winforms 桌面应用程序正在加载具有相同接口(interface)类型的多个 MEF 部件。 问题:当我尝试加载多个相同类型时,出现以下异常: 组成保持不变。由于以下错误,更改被拒绝:
我有一个内容查询 Web 部件,它按内容类型对网站集进行查询。我已按内容类型对其进行了分组,因此我有: -- Agenda (Content Type) ----Agenda #1 ----Agend
考虑以下 SharePoint 站点层次结构: - Site Collection - Site1 - Subsite1 - AnotherSubsite1
好吧,在我的 SharePoint (2013) 网站中,我制作了一个简单的 JavaScript Web 部件,每五分钟刷新一次页面。我去调整时间,在刷新前输入等待时间的地方退格,然后不假思索地退出
我不知道 Sharepoint 脚本,我的同事也不知道 JavaScript。他使用了他在 http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=22
我是一名优秀的程序员,十分优秀!