在 WordPress 上的自定义类别页面模板上添加 Jquery Post 滑块?

发布于 2024-12-23 13:21:26 字数 1713 浏览 4 评论 0原文

我已经使用category-[id].php 制作了一个自定义类别模板,现在一切正常。我想做的就是在自定义类别页面上添加带有特色图像的 Jquery Post 滑块。目前,我的主题允许我将其添加到主页。目前,我已在主题管理面板中为此滑块定义了一个类别。

我的主页有一个“精选”类别的滑块。我怎样才能在我的自定义类别模板页面上有这样类型的滑块,显示该类别最近的 4 或 5 篇帖子[与主页不同]以及“特色图像”?我可以使用主题的相同特色滑块功能来创建新滑块,如我在自定义类别模板页面上所述吗?

** 我的 WordPress 主题是 Skyli 的 LondonLive。

index.php 代码:

<?php get_header(); ?>

<?php if( get_option('skyali_londonlive_featured_style') != 'slider_long' AND  get_option('skyali_londonlive_featured_style') != ''){ ?>

<?php  if($video_ != 'true'){  ?>

<?php include_once('includes/'.display_featured().'.php'); // include featured ?>

<?php } else { ?>

<?php include_once('includes/featured_2.php'); } ?>

<?php } ?>

<?php if(get_option('skyali_londonlive_slider') != '' && get_option('skyali_londonlive_slider') != 'disable'){ ?>

<?php include_once('includes/slider.php'); ?>
..........

特色滑块代码:

<div id="featured" <?php featured_option(); ?>>
<?php  $featured_cat = get_option('skyali_londonlive_featured_cats'); //get featured category ?>
<ul class="ui-tabs-nav">
<?php $i = 1; ?>
<?php
//list featured slide previews
$featured = new WP_Query('showposts=4&cat='.$featured_cat.''); while($featured->have_posts()) : $featured->the_post(); ?>
<?php if($i == 1){$select_element = 'ui-tabs-selected';} else { $select_element = ''; } ?>
.........
//list featured slide show div's 
$featured = new WP_Query('showposts=4&cat='.$featured_cat.''); while($featured->have_posts()) : $featured->the_post(); ?>
<!-- <?php echo $i; ?> Content -->

I have made a custom category template using category-[id].php and it's fine now. All i am trying to do is to add a Jquery Post slider with featured images on custom category page. Currently, my theme allows me to add this to home page. Currently, i have defined a category in my theme admin panel for this slider.

My homepage has a slider for category "Featured" . How can i have such type of slider on my Custom Category Template page showing recent 4 or 5 posts from that category [different from the home page one] with "Featured Images" ? Can i use the same Featured slider function of my theme to have a new slider as i described on my custom category template page ?

** My Wordpress theme is LondonLive by Skyli.

index.php code:

<?php get_header(); ?>

<?php if( get_option('skyali_londonlive_featured_style') != 'slider_long' AND  get_option('skyali_londonlive_featured_style') != ''){ ?>

<?php  if($video_ != 'true'){  ?>

<?php include_once('includes/'.display_featured().'.php'); // include featured ?>

<?php } else { ?>

<?php include_once('includes/featured_2.php'); } ?>

<?php } ?>

<?php if(get_option('skyali_londonlive_slider') != '' && get_option('skyali_londonlive_slider') != 'disable'){ ?>

<?php include_once('includes/slider.php'); ?>
..........

Featured Slider Code:

<div id="featured" <?php featured_option(); ?>>
<?php  $featured_cat = get_option('skyali_londonlive_featured_cats'); //get featured category ?>
<ul class="ui-tabs-nav">
<?php $i = 1; ?>
<?php
//list featured slide previews
$featured = new WP_Query('showposts=4&cat='.$featured_cat.''); while($featured->have_posts()) : $featured->the_post(); ?>
<?php if($i == 1){$select_element = 'ui-tabs-selected';} else { $select_element = ''; } ?>
.........
//list featured slide show div's 
$featured = new WP_Query('showposts=4&cat='.$featured_cat.''); while($featured->have_posts()) : $featured->the_post(); ?>
<!-- <?php echo $i; ?> Content -->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2024-12-30 13:21:26

您应该能够从主题的 index.php 文件中复制/粘贴所需的大部分代码。它不是一个免费提供的主题,所以我自己无法查看该代码,但如果您查找

然后,您只需修改该代码中执行的查询,将其限制为您想要的类别。如果使用 get_posts,那么您的查询将如下所示:

$current_category = single_cat_title("", false);
$args = array(
    'numberposts'     => 5,
    'offset'          => 0,
    'category_name'   => $current_category,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'post_type'       => 'post',
    'post_status'     => 'publish' );

$recent_posts = get_posts( $args );

如果使用 WP_Query,您的查询应如下所示:

$current_category = single_cat_title("", false);
$cat_posts = new WP_Query('showposts=5&category_name='.$current_category);

while ($cat_posts->have_posts())

...

You should be able to copy/paste most of the code you need from the index.php file for your theme. Its not a freely available theme so I can't look at that code myself, but if you look for <div id="featured"> it should get you pretty close.

Then you'll just need to modify the query being performed in that code to limit it to just the category that you want. If it's using get_posts, then your query would look something like this:

$current_category = single_cat_title("", false);
$args = array(
    'numberposts'     => 5,
    'offset'          => 0,
    'category_name'   => $current_category,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'post_type'       => 'post',
    'post_status'     => 'publish' );

$recent_posts = get_posts( $args );

If it's using WP_Query, your query should look something like this:

$current_category = single_cat_title("", false);
$cat_posts = new WP_Query('showposts=5&category_name='.$current_category);

while ($cat_posts->have_posts())

...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文