- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基本的存档提要。
我正在尝试添加一个简单的按表单排序的下拉列表,它允许我按日期、标题和受欢迎程度对结果进行排序...
我已经有了它,但它并没有像我预期的那样工作。
我有一个下拉菜单,“onchange”获取选项的值,并将其添加到 URL 中。通过将值设置为 ?orderby=date&order=DESC 它可以工作...
但是,它会重新加载页面(这很好)并且不会保存所选选项的值...因此下拉字段不会显示所选的值...
如果我选择不同的值,它也不会删除该值。因此,如果选择,它将在 orderby=date&order=DESC 的末尾附加 ?orderby=date&order=ASC 。并且会继续这样做,这会导致问题。
第三,“观看次数”似乎不起作用,不确定根据浏览该页面的人数进行过滤的值应该是什么(这可能吗?!)
if ( have_posts() ) :
echo '<div class="posts-query">';?>
<div id="sortby"> SORT BY:
<select class="dropdown-class" name="sort-posts" id="sortbox" onchange="document.location.href=location.href+this.options[this.selectedIndex].value;">
<option disabled>Sort by</option>
<option value="?orderby=date&order=DESC">Newest</option>
<option value="?orderby=date&order=ASC">Oldest</option>
<option value="?orderby=title&order=ASC">A-Z Asc</option>
<option value="?orderby=title&order=DESC">A-Z Desc</option>
<option value="?orderby=views&order=ASC">Views Asc</option>
<option value="?orderby=views&order=DESC">Views Asc</option>
</select>
</div>
<?php while ( have_posts() ) : the_post(); ?>
<div class="query-post">
<div class="posts-image">
<?php the_post_thumbnail("thumbnail");?>
</div>
<div class="post-categories">
<?php $postType = get_post_type_object(get_post_type());
if ($postType) {
echo esc_html($postType->labels->singular_name);
} ?>
</div>
<div class="posts-title">
<a href="<?php the_permalink(); ?>">
<h3>
<?php the_title() ?>
</h3>
</a>
</div>
</div>
<?php endwhile; endif; ?>
有没有一种方法可以简单地按日期、标题和 View 对 WP_Query 进行排序,并且不仅可以将选项下拉列表中的所选结果保存为“已选择”,而且如果选择了新查询,还可以删除上一个查询从下拉列表中?
最佳答案
对于那些可能感兴趣的人,我使用以下代码解决了这个问题:
<div id="sortby"> SORT BY:
<select class="dropdown-class" name="sort-posts" id="sortbox" onchange="document.location.search=this.options[this.selectedIndex].value;">
<option disabled>Sort by</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'date' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?> value="?orderby=date&order=DESC">Newest</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'date' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?> value="?orderby=date&order=ASC">Oldest</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'title' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?> value="?orderby=date&order=DESC" value="?orderby=title&order=ASC">A-Z Asc</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'title' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?> value="?orderby=title&order=DESC">A-Z Desc</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'views' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?> value="?orderby=views&order=ASC">Views Asc</option>
<option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'views' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?> value="?orderby=views&order=DESC">Views Desc</option>
</select>
</div>
关于javascript - 通过自定义 wp_query CPT 上的下拉菜单进行简单排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574245/
在报警盗窃示例中,我无法理解 P(A|B,E) 表中的数字来自何处。我知道 P(B) 和 P(E) 是从有关领域的知识中选择的。但我不明白 CPT 中有多少值可以选择,哪些值必须计算才能使表格有效。我
我构建了一个表单,使用户能够从前端发布。我试图让它通过 wp_set_object_terms 的分类法,因为我使用自定义帖子类型和自定义分类法。这是我的代码: if(isset ($_POST['s
我们负责一个 WordPress 插件,作为其功能的一部分,它有一个名为“申请人”的自定义帖子类型。这些是希望购买特性的申请人,因此您可以在帖子中记录他们的联系方式和搜索要求等信息。 现在...我们发
例如,从 09:00am 到 09:05:am 理想情况下,我的情节从服务器获得 6 分。 - (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
我已经实现了 cptscatterplot 线。在我的应用程序中,我在标签下有条形图,并且将根据 yvalues 绘制 cptscatterplot 线。 如果值是空的,那么我将打破这条线,如果值是有
我正在显示自定义帖子类型的所有帖子,但我想按分类顺序显示它们。 我希望它看起来像这样: 第 1 期: post x post y 第 2 期: post z Term 3: post n 我的计划是为
有没有办法使用 CPTScatterPlot 为每个字段绘制单独的颜色,如下所示? 最佳答案 我找到了一个解决方法。我所做的只是创建多个 CPTScatterPlot 并用不同的颜色填充每个图。要实现
我想在我的 CPTScatterPlot 中突出显示某些感兴趣的部分。 搜索文档并查看演示应用程序,如果这是内置功能,演示应用程序没有提供任何见解。 基本上我想像这样转动CPTScatterPlot
我有两个 CPT,分别是“正装”和“休闲”,我想将它们放置在菜单中“仪表板”之后的位置。 我的自定义帖子类型中有以下代码: 'menu_position' => 2 结果如何显示为: “礼
我有一个基本的存档提要。 我正在尝试添加一个简单的按表单排序的下拉列表,它允许我按日期、标题和受欢迎程度对结果进行排序... 我已经有了它,但它并没有像我预期的那样工作。 我有一个下拉菜单,“onch
Plone 中的.cpt 模板和.pt 模板有什么区别?有吗? 最佳答案 .cpt 文件是 Controller 页面模板,.pt 文件是常规页面模板。 前者由 Formcontroller tool
需要获取在特定自定义帖子类型 (CTP) 中发帖的最后 5 位用户。由于我似乎无法找到一个 WordPress 函数来执行此操作,因此我正在尝试编写一个自定义查询。 到目前为止,我已经得到了这个以获得
我想构建一个依赖于其他分类变量的离散 (pymc.Categorical) 变量的贝叶斯网络。作为simplest例如,假设变量 a 和 b 是分类变量并且 b 取决于 a 这是使用 pymc 对其进
现在,我可以使用 CPTScatterPlot 绘制这样的趋势图。 30 个点和红线相互连接。 但我想在每个点之间使用不同的线条颜色。 这是我正在尝试的代码 CPTXYGraph *graph
当您创建散点图时,它会自动标记图表上的点。我觉得这很烦人,想关闭它,因为它对我们正在做的事情没有用。有没有办法不删除所有标签? 明确地说,这些显示时没有添加任何注释。我想删除此默认行为。 我想删除图中
我要做的是在语句中设置值cpt DATE_ADD(firstqDate, INTERVAL @val DAY ) 让每次扫描循环都有一个新日期。 此语句是存储过程中的一行,其中 2 个值取决于日期和之
我不知道为什么会这样。我正在掌握 Grok 框架。在按照教程进行操作时,我遇到了这个错误。当使用 TAL:attributes 链接到 CSS 样式表时,索引页面会加载系统错误消息。索引文件称为 in
我正在使用 Core plot BarChart 应用带 RGB 的条形颜色不起作用..! 它只适用于主要颜色,如红色、绿色、蓝色、白色、紫色......! 我正在尝试应用橙色,但没有应用。任何人都可
我已经四处寻找解决方案,但我自己的代码还不够好,但也许对 PHP 有更多了解的人可以帮助我。 当客户添加新的顶级菜单链接时,我基本上需要在管理面板中创建自定义帖子类型。这可能吗? 我只有基本代码 fu
我正在遍历我的 CPT 类别,并且我想在每个循环中使用我的 ACF 字段。 'segments-overview', 'orderby' => 'date
我是一名优秀的程序员,十分优秀!