WordPress发布查询(WordPress post query)

如果他们是第843页的孩子,我正试图显示带有“医疗”标签的帖子,到目前为止,我一切都在工作。 我需要在这个if语句中获取一些HTML,以便我可以将它全部包含在div中,并且还为列表设置一个开始和结束ul。

有人可以帮我解决这个最后一个驼峰吗? 我只是不确定在哪里添加HTML。

<?php
if (843 == $post->post_parent) {
global $post;
$myposts = get_posts('numberposts=10&tag=medical&order=DESC');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;
}
?>

I am trying to show posts with the tag "medical" if they are a child of page 843, and so far, I have everything mostly working. I need to get some HTML within this if statement so that I can enclose it all in a div, and also to set an opening and closing ul for the list.

Can someone please help me get over this last hump? I'm just not sure where to add the HTML.

<?php
if (843 == $post->post_parent) {
global $post;
$myposts = get_posts('numberposts=10&tag=medical&order=DESC');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;
}
?>

原文:https://stackoverflow.com/questions/9318941
2024-05-06 18:05

满意答案

Impala支持窗口功能。 这个问题是一个“缺口和孤岛”问题,因此可以使用行数的差异来解决:

select id, state, min(date) as start_date, max(date) as end_date
from (select t.*,
             row_number() over (partition by id order by date) as seqnum_id,
             row_number() over (partition by id, state order by date) as seqnum_isd
      from table t
     ) t
group by id, state, (seqnum_id - seqnum_isd);

差异的逻辑并不困难,但是当你第一次学习它时却很棘手。 它有助于运行子查询并查看行号值是什么 - 以及差异定义每个组的原因。


Impala supports window functions. This problem is a "gap-and-islands" problem, so it can be solved using a difference of row numbers:

select id, state, min(date) as start_date, max(date) as end_date
from (select t.*,
             row_number() over (partition by id order by date) as seqnum_id,
             row_number() over (partition by id, state order by date) as seqnum_isd
      from table t
     ) t
group by id, state, (seqnum_id - seqnum_isd);

The logic for the difference is not difficult, but tricky when you first learn it. It helps to run the subquery and see what the row number values are -- and why the difference defines each group.

相关问答

更多

SQL将日期缩小到“开始 - 结束”范围(SQL reduce dates to range “start - end”)

Impala支持窗口功能。 这个问题是一个“缺口和孤岛”问题,因此可以使用行数的差异来解决: select id, state, min(date) as start_date, max(date) as end_date from (select t.*, row_number() over (partition by id order by date) as seqnum_id, row_number() over (partition by...

根据开始日期和结束日期将多行插入SQL Server(Insert multiple rows into SQL Server based on start and end dates)

一如往常有几种方法。 这里是其中的一些: 您可以在应用程序中编写循环遍历日期的代码,并每天插入一条记录。 (通常是最糟糕的设计) 您可以调用一些SQL脚本在数据库中完成所有操作。 您可以将SQL脚本包装在存储过程中,并传入开始日期和结束日期,并获取存储过程为您执行此操作。 您可以交叉连接到预先存在的计数表并使用它来生成记录。 如果你能提供 - 您正在使用的SQL Server版本 - 桌子看起来像什么 - 你是否使用C#或VB 然后我们可以进一步提供帮助,因为将日期传递到数据库可能很困难。 如果您...

如何遍历日期范围?(How to iterate through range of Dates?)

使用DateTime模块。 这是一个简单的例子,它列出了前十天: use 5.012; use warnings; use DateTime; my $end = DateTime->now; my $day = $end->clone->subtract( days => 10 ); # ten days ago while ($day < $end) { say $day; $day->add( days => 1 ); # move along to next da...

验证日期的开始和结束(validating dates start and end)

编辑:刚刚注意到你使用的是Bootstrap Datepicker而不是jQuery UI Datepicker。 每当'开始日期'输入更改时,从Datepicker获取值并更新'结束日期' minDate / startDate属性 回答Bootstrap Datepicker $('.fromDate input').on("changeDate", function(){ var minDate = $(this).datepicker( "getDate" ); $('.toDat...

SQL多个开始日期到结束日期(SQL multiple start dates to end date)

使用自联接获取下一条记录 ;WITH CTE AS ( SELECT ROW_NUMBER() OVER(ORDER BY [Cluster Start Date])RNO,* FROM YOURTABLE ) SELECT C1.ClientID,C1.RefAd1,C1.[Cluster Start Date],C2.[Cluster Start Date] [Cluster End Date] FROM CTE C1 LEFT JOIN CTE C2 ON C1.RNO=C2...

如何根据开始和结束日期复制记录(How to Duplicate Records According to Start and End Dates)

您可以在SQL Server和Postgres中使用递归CTE,但语法略有不同。 而且,Postgres中有一个更简单的方法。 所以,在SQL Server中,你可以这样做: with cte as ( select username, startdate, weekday, enddate from t union all select username, dateadd(day, 1, startdate) weekday, enddate ...

给定一个开始日期和结束日期...在C#中查找范围内的所有日期(Given a start and end date… find all dates within range in C#)

您可以填写所有日期的列表: DateTime begin = //some start date DateTime end = //some end date List<DateTime> dates = new List<DateTime>(); for(DateTime date = begin; date <= end; date = date.AddDays(1)) { dates.Add(date); } You can fill a list with all the dat...

给出开始日期和结束日期的日期列表(Generating a list of dates given the start and end dates)

编辑: 正如评论中所讨论的,这显然是您所需要的。 Sub GenerateDates() Dim FirstDate As Date Dim LastDate As Date Dim NextDate As Date FirstDate = Range("startdate").Value LastDate = Range("enddate").Value NextDate = FirstDate Range("tripdays").Select 'selection of columns ...

如何获得SQL Server中两个日期之间的所有星期的开始和结束日期?(how to get the start and end dates of all weeks between two dates in SQL server?)

您可以使用递归CTE生成日期列表: ;with cte as ( select @sDate StartDate, DATEADD(wk, DATEDIFF(wk, 0, @sDate), 6) EndDate union all select dateadd(ww, 1, StartDate), dateadd(ww, 1, EndDate) from cte where dateadd(ww, 1, StartDate)<= @eDate ) selec...

SQL查询创建开始日期和结束日期(SQL Query Creating Start and End Dates)

我不会在这里放置这个ID,因为我发现它在查询中无关紧要。 如果你希望你以后再说。 这是一个MSSQL查询。 select tb1.date as startdate,dateadd(d,-1,tb2.date) as enddate from the_table tb1 join the_table tb2 on tb2.date>tb1.date left join the_table tb3 on tb1.date<tb3.date and tb3.date<tb2.date where tb...

相关文章

更多

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

Solr 使用自定义 Query Parser

原文出处:http://blog.chenlb.com/2010/08/solr-use-custom ...

常用HQL(Hibernate Query Language)查询

查询一个对象(实体类必须有一个不带参数的构造方法),使用select查询,基于投影的查询,通过在列表中 ...

solr学习笔记二-------solr query查询的参数

初步接触solr是对其query的各个参数都不是很了解,现在做一个总结,以便日后查看使用 各个参数及意 ...

MongoDB学习 (五):查询操作符(Query Operators).1st

查询操作符(Query Operators)可以让我们写出复杂查询条件,让我们使用的过程更加灵活。官方 ...

solr delete query

Solr1.4 Both delete by id and delete by query can b ...

solr delete query

Solr1.4 Both delete by id and delete by query can b ...

LeetCode:Word Break(DP)

题目地址:http://oj.leetcode.com/problems/word-break/ 简单 ...

httpclient post 请求

httpclient post请求与get请求的区别主要是httpclient.execute对象 ...

Mysql错误:Ignoring query to other database解决方法

用source c:\xxx.sql,出现Ignoring query to other databa ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本