不通过WP_query显示的热门帖子(Popular Posts Not Showing Through WP_query)
我想根据用户的要求制作侧边栏,但是在这个侧栏用户想要显示博客的热门帖子,我会做更多的搜索以显示它,但它的所有内容都是徒劳的。 :(这是我的代码!
<div class="ms_recent"> <h5>Popular posts</h5> <?php $blog_papular = array( 'posts_per_page'=>5, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', ); $wp_query_papular=new WP_Query($blog_papular); while($wp_query_papular->have_posts()) { $wp_query_papular->the_post(); ?> <div class="ms_articles"> <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail('footer_page_image'); ?> <span><?php echo get_the_date('F j'); ?></span> <p><?php echo excerpt('8'); ?></p></a> </div> <?php } ?> </div>
这里有人知道我误解的地方吗?
I want to make sidebar as per user requirements but in this sidebar user want to show popular posts of blog and I do more searching to show it but all its vain. :( Here is my code!
<div class="ms_recent"> <h5>Popular posts</h5> <?php $blog_papular = array( 'posts_per_page'=>5, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', ); $wp_query_papular=new WP_Query($blog_papular); while($wp_query_papular->have_posts()) { $wp_query_papular->the_post(); ?> <div class="ms_articles"> <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail('footer_page_image'); ?> <span><?php echo get_the_date('F j'); ?></span> <p><?php echo excerpt('8'); ?></p></a> </div> <?php } ?> </div>
Here anyone know where I mistaken?
原文:https://stackoverflow.com/questions/40838469
最满意答案
但它也有几个空白记录(我认为这些记录与其他学校的校园记录有关)。
这些“空白”记录是为了给学校增加新的校园。 您可以使用CampusInline上的“额外”属性来控制空行数。
如果我向外键添加“unique = True”(如上面的模型所示),空白记录消失,并且看起来都很好。 不幸的是,我还在内联底部松开链接以添加新校园。
如果您在“学校”字段添加“独特”,那意味着学校只能在校园桌上出现一次。 对于外键,这通常不会(通常)很有意义。
but it also has several blank records (which I assume are related to the campus records for other schools).
Those "blank" records are for adding new campuses to the school. You can use the "extra" attribute on your CampusInline to control the number of blank lines.
If I add "unique=True" to the foreign key (as shown in the model above), the blank records disappear and all looks good. Unfortunately, I also loos the link at the bottom of the inline to add a new campus.
If you add "unique" to the "school" field, that would mean that a school could only appear once in the campus table. Which doesn't (usually) make much sense for a foreign key.
相关问答
更多-
from django.utils.functional import curry class DetailsInline(admin.TabularInline): model = Details formset = DetailsFormset extra = 3 def get_formset(self, request, obj=None, **kwargs): initial = [] if request.method == " ...
-
您可以为您自定义模板TabularInline,使其看起来像你想要的样子。 我认为这是一个更好的主意,然后黑客__unicode__ : class PhotoInline(admin.TabularInline): model = Photo template = 'photologue/photoinline.html' 最简单的创建方法是复制和自定义默认的django/contrib/admin/templates/admin/edit_inline/tabular.html模板。 ...
-
您可以向TabularInline添加函数,然后将它们显示为字段: class MyTabularInline(admin.TabularInline): model = MyModel readonly_fields = ['decrypt_first_field', 'decrypt_second_field'] def decrypt_first_field(self, obj): if obj.first_field: return ...
-
Django我可以将tabularinline字段分成多行吗?(Django can I split tabularinline fields into multiple lines?)[2023-10-06]
使用可以使用StackedInline Use can use a StackedInline instead -
但它也有几个空白记录(我认为这些记录与其他学校的校园记录有关)。 这些“空白”记录是为了给学校增加新的校园。 您可以使用CampusInline上的“额外”属性来控制空行数。 如果我向外键添加“unique = True”(如上面的模型所示),空白记录消失,并且看起来都很好。 不幸的是,我还在内联底部松开链接以添加新校园。 如果您在“学校”字段添加“独特”,那意味着学校只能在校园桌上出现一次。 对于外键,这通常不会(通常)很有意义。 but it also has several blank records ...
-
在TabularInline Django管理表单中覆盖formset(Overriding formset in TabularInline Django admin form)[2022-08-13]
您应该使用django.forms.models.inlineformset_factory而不是formset_factory The answer to my question didn't have to do with how I was structuring my forms, but rather how I was joining fields on my models. I had the following structure in my models: class App(models ... -
在django admin中设置admin.TabularInline的数量(set numbers of admin.TabularInline in django admin)[2023-01-16]
将内联的extra属性设置为1。 Set your inline's extra attribute to 1. -
尝试将extra设置为0 class RirDataInline(admin.TabularInline): model = RirData fields = ['netname', 'inetnum', 'review_status', 'active'] readonly_fields = fields can_delete = False show_change_link = True extra = 0 Try to set extra to 0 c ...
-
为什么不重写管理模板来添加一些CSS? 例如,在templates / admin / testapp / author / change_form.html中: {% extends 'admin/change_form.html' %} {% block content %} {{ block.super }} ...
-
尝试在浏览器中调试https://github.com/applegrew/django-select2/blob/master/django_select2/static/js/select2.js#L1301 (包括非min版本) 或者只是删除这一行https://github.com/applegrew/django-select2/blob/master/django_select2/static/js/select2.js#L1328 Try debug https://github.com/ap ...