简体   繁体   English

我要拉最新帖子并嵌入其他2个第一结果帖子吗?

[英]I want to pull latest post and embed other 2 first result posts?

User will search/submit at the same time. 用户将同时搜索/提交。

<input id="user-submitted-title" name="user-submitted-title" type="text" value="" placeholder="<?php esc_attr_e('Search', 'usp'); ?>"<?php if (usp_check_required('usp_title')) echo $usp_required; ?> class="usp-input">

This one is the form from wordpress plugin, and its only for a title, and I use that only. 这是来自wordpress插件的表格,仅用于标题,我仅使用它。 When user submits this by title, I have other code which will add post into my wordpress site by bunch of other codes. 当用户按标题提交时,我还有其他代码,这些代码将通过一堆其他代码将帖子添加到我的wordpress网站中。

I already have a query: 我已经有一个查询:

<?php
include 'wp-load.php';

$args = array(
    'post_type' => 'post',
    'posts_per_page'    => 1
    );

$query = new WP_Query($args);

if($query->have_posts()):
    $data = '';
    while($query->have_posts()):$query->the_post();
    $data .= '<h1 style="text-align: center; margin: 0; margin: 0px 0 10px 0px;">'.get_the_title().'</h1>';
    $data .= '<div class="description">'.do_shortcode(get_the_content()).'</div>';

endwhile;endif;
echo $data;  ?>

So this one basically shows their or the latest post from the wordpress site on same page with search/submit button. 因此,这基本上是通过搜索/提交按钮在同一页面上的wordpress网站上显示他们的最新帖子。

Except this I want to acomplish that to get and embed content of the other site posts found by query from input and embed them after the one above. 除此之外,我想补充一下,以获取并嵌入通过输入从查询中找到的其他网站帖子的内容,并将其嵌入到上述内容之后。

I tried something with new query like: 我尝试了一些新查询,例如:

    <?php
include 'wp-load.php';

    $querys = new WP_Query('post_title='.get_the_title().'');

    if($querys->have_posts()) : while($querys->have_posts()) : $querys->the_post();
    if (has_post_thumbnail()) {
        ?>
            <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
        <?php
    }
    ?>
    <h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?php
    the_excerpt(); // or the_content(); for full post content
    endwhile;endif;
?>

But this $querys = new WP_Query('post_title='.get_the_title().''); 但这$querys = new WP_Query('post_title='.get_the_title().''); does not seem to work. 似乎不起作用。 How to do this? 这个怎么做? Plus this second query does not work for links, outside loop, how to solve that too? 再加上第二个查询不适用于链接,外部循环,该如何解决呢?

Have you tried $querys = new WP_Query('post_title="'.get_the_title().'"'); 您是否尝试过$querys = new WP_Query('post_title="'.get_the_title().'"'); this one. 这个。 or may be this one 或者可能是这个

$querys = new WP_Query('s' => get_the_title()); // custom search query

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress的:创建2个循环。 首先是一个即时贴或最新帖子。 所有其他职位第二 - Wordpress: creating 2 loops. First for one sticky OR the latest post. Second for all other posts Facebook - 嵌入来自不同用户的最新帖子 - Facebook - embed latest posts from different users 如何显示第一篇文章与其他文章不同? - How to show first post differently from other posts? 仅从最新的帖子Feed,wordpress中排除一个类别的第一篇帖子 - Exclude only first post from one category from the latest posts feed, wordpress Wordpress帖子页面 - 循环没有显示最新帖子 - Wordpress Posts Page - loop is not showing latest post 从下到上先加载最新帖子 - Load Latest Posts First From Bottom To Top 如何将3个最新的Wordpress帖子嵌入到外部网站的单独div中? - How to embed 3 latest Wordpress posts into separate divs in an external website? 显示六个最新的PhpBB帖子,而不是六个最新帖子 - Showing six latest PhpBB posts instead of six copies of latest post 最近的4个帖子(不包括类别),追加已排除的类别中的最新帖子 - Latest 4 posts excluding category, append latest post from excluded category Laravel:如何让 CKEditor 显示帖子正文的前几个单词而不改变其他帖子的样式 - Laravel: How to get CKEditor to display first few words of post body without altering the styling of other posts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM