Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在内容过滤器中显示自定义帖子类型帖子和元数据_Php_Wordpress_Plugins_Thumbnails - Fatal编程技术网

Php 在内容过滤器中显示自定义帖子类型帖子和元数据

Php 在内容过滤器中显示自定义帖子类型帖子和元数据,php,wordpress,plugins,thumbnails,Php,Wordpress,Plugins,Thumbnails,我正在我的mu-plugins.php文件中使用它// function new_default_content($content) { global $post; if ($post->post_type == 'textures') { $content .='<li> <figure> <?php the_post_thumbnail('thummy'); ?> <figcaption> <h3><?php

我正在我的mu-plugins.php文件中使用它//

function new_default_content($content) {
global $post;
if ($post->post_type == 'textures') {
$content .='<li>
<figure>
   <?php the_post_thumbnail('thummy'); ?>
   <figcaption>
<h3><?php the_title(); ?></h3>
<span>Cool stuff brah.</span>

<?php 
 if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a>'; }?>
                    </figcaption>
                </figure>
            </li>';
}
return $content;
}
add_filter('the_content', 'new_default_content');
<div id="container" class="clearfix">
<div id="left-content">
    <?php get_sidebar('two');?> 
</div>

<div id="right-content">
    <h1><?php wp_title(''); ?></h1>

    <ul class="grid cs-style-3">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>
    </ul>
</div><!--right-content-->
</div><!--container-->

<?php get_footer(); ?>
function新建默认内容($content){
全球$员额;
如果($post->post_type=='textures'){
$content.='
  • 很酷的东西,布拉。
  • '; } 返回$content; } 添加_过滤器(“_内容”、“新_默认_内容”);
    在我的页面模板中,我使用
    显示所有内容

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    更新/
    整页模板代码

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    
    


    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    但是我收到了这个错误//
    解析错误:语法错误,第15行/home/xxx/public\u html/domain.com/testing/wp-content/mu-plugins/must-use.php中出现意外的T_字符串

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    我尝试这种显示内容的方法是因为我想使用WP Members插件,我意识到该插件只适用于
    内容()中的内容

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    因此,我的问题是如何修复我在上面发布的代码,以正确的方式显示标题、缩略图、链接等?

    function new\u default\u content($content){
    
    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    function new_default_content($content) {
    global $post;
    if ($post->post_type == 'textures') {
    $content .='<li>';
    $content .='<figure>';
    $content .= the_post_thumbnail('thummy');
    $content .= '<figcaption>';
    $content .= '<h3>';
    $content .= the_title();
    $content .= '</h3>';
    $content .= '<span>Cool stuff brah.</span>';
    
     if ( has_post_thumbnail()) {
        $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
        echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a>'; 
     }
            $content .= '</figcaption>';
        $content .= '</figure>';
    $content .= '</li>';
    }
    return $content;
    }
    add_filter('the_content', 'new_default_content');
    
    全球$员额; 如果($post->post_type=='textures'){ $content.='
  • '; $content.=''; $content.=发布缩略图('thummy'); $content.=''; $content.=''; $content.=_title(); $content.=''; $content.=“酷东西布拉”; 如果(具有\u post\u缩略图()){ $large\u image\u url=wp\u get\u attachment\u image\u src(get\u post\u thumbnail\u id(),'large'); 回声'; } $content.=''; $content.=''; $content.='
  • '; } 返回$content; } 添加_过滤器(“_内容”、“新_默认_内容”);

    试试这个代码。如果您仍然遇到相同的错误,我们将进行检查。

    找到了解决方案。
    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    我记得您可以在短代码中添加内容。
    因此,我创建了自己的短代码
    [textures\u content]

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    然后使用下面粘贴的代码显示
    函数/

    <div id="container" class="clearfix">
    <div id="left-content">
        <?php get_sidebar('two');?> 
    </div>
    
    <div id="right-content">
        <h1><?php wp_title(''); ?></h1>
    
        <ul class="grid cs-style-3">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif; ?>
        </ul>
    </div><!--right-content-->
    </div><!--container-->
    
    <?php get_footer(); ?>
    
    add_shortcode( 'textures_content', 'textures_shortcode' );
    function textures_shortcode( $atts ) {
        ob_start();
        $query = new WP_Query( array(
            'post_type' => 'textures',
            'posts_per_page' => -1,
            'order' => 'ASC',
            'orderby' => 'date',
        ) );
        if ( $query->have_posts() ) { ?>
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                    <li>
                        <figure>
                            <?php the_post_thumbnail('thummy'); ?>
                            <figcaption>
                                <h3><?php the_title(); ?></h3>
                                <?php if ( has_post_thumbnail()) {
                                $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
                                echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a>'; }?>
                            </figcaption>
                        </figure>
                    </li>
                <?php endwhile;
                wp_reset_postdata(); ?>
        <?php $myvariable = ob_get_clean();
        return $myvariable;
        }
    } 
    
    add_shortcode('textures_content','textures_shortcode');
    函数纹理\u短代码($atts){
    ob_start();
    $query=新的WP\U查询(数组(
    “post_type”=>“纹理”,
    “每页帖子数”=>-1,
    “订单”=>“ASC”,
    'orderby'=>'date',
    ) );
    如果($query->have_posts()){?>
    

  • 如果您遗漏了引号或大括号,请检查它们。@Pranita老实说,我不熟悉wordpress过滤器,所以我不确定代码应该是什么样子。但是谢谢。我已经回复了更正的代码。检查您是否有错误。我尝试了提供的代码,非常感谢您的帮助!但问题仍然存在:/I更新了我的帖子并添加了d我的模板页面文件中的代码。当我从WP注销时,注册表单和登录表单会完美显示。但是当我登录并查看我标记为仅供会员使用的页面时,内容区域是空白的。如果你愿意继续帮助我,我可以发布截图或粘贴任何需要的代码。将上述功能放在有趣的地方如果你能发送一个你网站的链接,我们会检查到底出了什么问题,并创建一个虚拟用户进行测试。我最初在mu-plugins.php中有代码,但我按照你的说明将其添加到functions.php,但问题仍然存在。我会在我的问题中发布链接,以便在问题解决了。