使用PHP在WP中“主题化”我的滑块

使用PHP在WP中“主题化”我的滑块,php,jquery,wordpress,Php,Jquery,Wordpress,我在自定义Wordpress主题的内容上方实现了一个非常基本的“特色列表-图像滑块”。我想知道如何在两者之间硬编码PHP,将我的滑块与我的“主题”连接起来。我正在尝试“主题”滑块,以便通过“最近的帖子”或“类别”来提取内容。我如何设置“特色IMG”在滑块中显示为照片,并在列表区域中的我列出的缩略图部分中显示 这是我从jqueryi插件上获得的一个屏幕截图; 他们的演示坏了,所以 下面是我实现的标记 最新更新:仍在尝试获取图像以吸引用户。我试过Suni的建议,但仍然无法让他们在滑块内移动,最终在滑

我在自定义Wordpress主题的内容上方实现了一个非常基本的“特色列表-图像滑块”。我想知道如何在两者之间硬编码PHP,将我的滑块与我的“主题”连接起来。我正在尝试“主题”滑块,以便通过“最近的帖子”或“类别”来提取内容。我如何设置“特色IMG”在滑块中显示为照片,并在列表区域中的我列出的缩略图部分中显示

这是我从jqueryi插件上获得的一个屏幕截图; 他们的演示坏了,所以

下面是我实现的标记

最新更新:仍在尝试获取图像以吸引用户。我试过Suni的建议,但仍然无法让他们在滑块内移动,最终在滑块外移动

以下是我尝试过的一些方法:


我会这样做的

你需要在你想要使用的帖子上有两个循环——一个用来创建标签,一个用来创建内容。为了避免执行两个DB查询,请将来自一个查询的帖子缓存在一个数组中,并在该数组上使用foreach循环

使用自定义查询获取要在滑块中使用的post对象:

免责声明:这不会一字不差地工作,但应该为您提供所需的框架


我会这样做的

你需要在你想要使用的帖子上有两个循环——一个用来创建标签,一个用来创建内容。为了避免执行两个DB查询,请将来自一个查询的帖子缓存在一个数组中,并在该数组上使用foreach循环

使用自定义查询获取要在滑块中使用的post对象:

免责声明:这不会一字不差地工作,但应该为您提供所需的框架

下面是代码。。未经测试

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme'

 */

//get_header(); ?>        
<div id="content"> 

<?php if (have_posts()) : ?>

<!--Your slider code goes here-->

<?php 
$args = array(
              'numberposts'     => 5,
              'orderby'         => 'post_date',
              'order'           => 'DESC'
);
$posts_array = get_posts( $args ); 
?>       

<div id="featured" >  
<ul class="ui-tabs-nav">

<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?> 

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-<?php echo $i; ?>">
  <a href="#fragment-1"><img src="" alt="" style="display:none;"/>
    <span>
      <?php the_title(); ?><br />
      <p class="info" style="padding-left:10px;"><?php the_excerpt(); ?></p>
    </span>
  </a>
</li> 
<?php $i++; 
endforeach; ?>
</ul>
<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?>

<!-- First Content -->  
<div id="fragment-<?php echo $i; ?>" class="ui-tabs-panel" style="">
  <img src="<?php the_post_thumbnail('slider_image'); ?>" alt="" />  
  <div class="info">
    <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
    <p><?php the_excerpt(); ?><a href="<?php the_permalink(); ?>" >read more</a></p>  
  </div>  
</div>  
<?php $i++; endforeach; ?>


</div>  

<!--Your slider code goes here-->
<!-- End Featured Lists Image Slider -->        

<?php endif; ?>
下面是代码。。未经测试

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme'

 */

//get_header(); ?>        
<div id="content"> 

<?php if (have_posts()) : ?>

<!--Your slider code goes here-->

<?php 
$args = array(
              'numberposts'     => 5,
              'orderby'         => 'post_date',
              'order'           => 'DESC'
);
$posts_array = get_posts( $args ); 
?>       

<div id="featured" >  
<ul class="ui-tabs-nav">

<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?> 

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-<?php echo $i; ?>">
  <a href="#fragment-1"><img src="" alt="" style="display:none;"/>
    <span>
      <?php the_title(); ?><br />
      <p class="info" style="padding-left:10px;"><?php the_excerpt(); ?></p>
    </span>
  </a>
</li> 
<?php $i++; 
endforeach; ?>
</ul>
<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?>

<!-- First Content -->  
<div id="fragment-<?php echo $i; ?>" class="ui-tabs-panel" style="">
  <img src="<?php the_post_thumbnail('slider_image'); ?>" alt="" />  
  <div class="info">
    <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
    <p><?php the_excerpt(); ?><a href="<?php the_permalink(); ?>" >read more</a></p>  
  </div>  
</div>  
<?php $i++; endforeach; ?>


</div>  

<!--Your slider code goes here-->
<!-- End Featured Lists Image Slider -->        

<?php endif; ?>

虽然你认为它是基本的,但它比你想象的要多。几个小时已经证明了这一点!但是,建议呢?试着从这个开始。你需要一个自定义循环。你能提供一个演示链接吗?你在哪里工作?所以我们可以帮助你虽然你认为这是基本的,但它比你想象的要多。几个小时已经证明了这一点!但是,建议呢?试着从这个开始。你需要一个自定义循环。你能提供一个演示链接吗?你在哪里工作?因此,我们可以帮助您我测试了这个解决方案,它使我尽可能地测试它,也就是说,我不能测试javascript部分。唯一的小错误是第一个列表没有结束ul标记。我会编辑它,但我还没有编辑权限。太棒了,谢谢!关于使用“特色图片”来填充滑块有什么建议吗?嗨,Cam,您使用的是“\u post\u thumbnail$large\u image\u url=wp\u get\u attachment\u image\u src get\u post\u thumbnail\u id”“large”;让我知道它是否清晰..谢谢Sunil;因此,添加以下内容:我已经阅读了要在循环中添加的状态/或者我应该在滑块中添加吗?我测试了这个解决方案,并且它在我可以测试的范围内工作,也就是说,我无法测试javascript部分。唯一的小错误是第一个列表没有结束ul标记。我会编辑它,但我还没有编辑权限。太棒了,谢谢!关于使用“特色图片”来填充滑块有什么建议吗?嗨,Cam,您使用的是“\u post\u thumbnail$large\u image\u url=wp\u get\u attachment\u image\u src get\u post\u thumbnail\u id”“large”;让我知道它是否清晰..谢谢Sunil;因此,添加以下内容:我已经阅读了要在循环中添加的状态/还是应该在滑块中添加?
<?php

$post_data = array();

// Use a custom query to get the posts you want for your slider
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();

    $post_data[] = $post;

endwhile;

// Reset Post Data
wp_reset_postdata();

?>

<div id="featured" >

    <ul class="ui-tabs-nav">  

    <?php 
    foreach($post_data as $key => $post){

      // Out put the markup + data from the $post object that you need for your tabs

    } 
    ?>

    </ul>

    <?php 
    foreach($post_data as $key => $post){

      // Out put the markup + data from the $post object that you need for your slider fragments

    } 
    ?>

</div>
<?php
/**
 * @package WordPress
 * @subpackage Default_Theme'

 */

//get_header(); ?>        
<div id="content"> 

<?php if (have_posts()) : ?>

<!--Your slider code goes here-->

<?php 
$args = array(
              'numberposts'     => 5,
              'orderby'         => 'post_date',
              'order'           => 'DESC'
);
$posts_array = get_posts( $args ); 
?>       

<div id="featured" >  
<ul class="ui-tabs-nav">

<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?> 

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-<?php echo $i; ?>">
  <a href="#fragment-1"><img src="" alt="" style="display:none;"/>
    <span>
      <?php the_title(); ?><br />
      <p class="info" style="padding-left:10px;"><?php the_excerpt(); ?></p>
    </span>
  </a>
</li> 
<?php $i++; 
endforeach; ?>
</ul>
<?php
$i = 1;
foreach ($posts_array as $post) :  setup_postdata($post); 
?>

<!-- First Content -->  
<div id="fragment-<?php echo $i; ?>" class="ui-tabs-panel" style="">
  <img src="<?php the_post_thumbnail('slider_image'); ?>" alt="" />  
  <div class="info">
    <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
    <p><?php the_excerpt(); ?><a href="<?php the_permalink(); ?>" >read more</a></p>  
  </div>  
</div>  
<?php $i++; endforeach; ?>


</div>  

<!--Your slider code goes here-->
<!-- End Featured Lists Image Slider -->        

<?php endif; ?>