Wordpress如何删除从页面而不是从帖子中读取更多链接

时间:2017-06-26 15:24:57

标签: html wordpress

我有一个Wordpress网站已经阅读了更多链接添加到content.php中的“>阅读更多»

我想阅读更多链接,只显示在我的帖子中,而不是在我的页面中。 当我点击我的一个页面时,我看到了更多链接,这些链接不起作用,不应该在那里。

的index.php

   <?php

get_header();

?>

<div class="container">

<div class="secondary-column">
    <?php dynamic_sidebar('sidebar1');// sinu widgets sidebar ?> 
</div>

<div class="post-content">

<?php

if (have_posts()) :
    while (have_posts()) : the_post();

    get_template_part('content', get_post_format());  // dynamically include the post format - get_post_format() 
    endwhile;

    else :
        echo '<p>No content found</p>';

    endif;

?>

    <div class="pagination">
        <?php
            echo paginate_links();
        ?>
    </div>

<?php

get_footer();

?>

CONTENT.PHP

<article class="post <?php if ( has_post_thumbnail() ) { ?>has-thumbnail <?php } ?>">


    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    <p class="post-info"><?php the_time('F j, Y g:i a'); ?> | by <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a> | Posted in

        <?php

        $categories = get_the_category();
        $separator = ", ";
        $output = '';

        if ($categories) {

            foreach ($categories as $category) {

                $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>'  . $separator;

            }

            echo trim($output, $separator);
        }

        ?>

        </p>

        <div class="post-image">

            <div class="post-thumbnail">
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
            </div><!-- /post-thumbnail -->


            <p>
                <?php echo get_the_excerpt(); ?>
                <a href="<?php the_permalink(); ?>">Read more&raquo;</a>
            </p>


        </div>



</article>

single.php中

    <?php

get_header();

?>


<div class="container">

<div class="secondary-column">
        <?php dynamic_sidebar('sidebar1'); ?>
</div>

<div class="post-content">

<?php

if (have_posts()) :
    while (have_posts()) : the_post(); ?>


    <article class="post">
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

        <p class="post-info"><?php the_time('F j, Y g:i a'); ?> | by <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a> | Posted in

            <?php

            $categories = get_the_category();
            $separator = ", ";
            $output = '';

            if ($categories) {

                foreach ($categories as $category) {

                    $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>'  . $separator;

                }

                echo trim($output, $separator);         
            }

            ?>
            <div class="overlay-con"></div>
            <div class="lightbox post-image">
                <?php the_post_thumbnail(); ?>
                <?php the_content(''); ?>
            </div>  
            </p>

    </article>

    <?php endwhile;

    else :
        echo '<p>No content found</p>';

    endif;

    // If comments are open or we have at least one comment, load up the comment template.  // COMMENT
    if ( comments_open() || get_comments_number() ) {
                comments_template();
    }




get_footer();

?>

FUNCTIONS.PHP

<?php


function twentyfourteen_child_scripts() {
    wp_enqueue_script( 'extra js', get_stylesheet_directory_uri() . '/js/extra.js');
}

add_action( 'wp_enqueue_scripts', 'twentyfourteen_child_scripts' );


 wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/jquery-3.2.0.min.js');


function learningWordPress_resources() {
    wp_enqueue_style('style', get_stylesheet_uri());
}

add_action('wp_enqueue_scripts', 'learningWordPress_resources');



function get_top_ancestor_id() {

    global $post;

    if($post->post_parent){
       $ancestors = array_reverse(get_post_ancestors($post->ID));
       return $ancestors[0];
    }

    return $post->ID;
}


// Does page have children?
function has_children() {
    global $post;
    $pages = get_pages('child_of=' . $post->ID);
    return count($pages);

}

// Customize excerpt word count length
function custom_excerpt_length() {
    return 20;
}

add_filter('excerpt_length', 'custom_excerpt_length');



function learningWordPress_setup() {   

    register_nav_menus(array(             
        'primary' => __( 'Primary Menu'),   
        'footer' => __( 'Footer Menu'),
    ));

    add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'video', 'status', 'audio', 'chat'));
    add_theme_support('post-thumbnails');

//add_theme_support('post-thumbnails','post-formats', array('aside', 'gallery', 'link')); // see annab errori
}

add_action('after_setup_theme', 'learningWordPress_setup');


function ourWidgetsInit() {

    register_sidebar( array(
        'name' => 'Sidebar',
        'id' => 'sidebar1',
        'before_widget' => '<div class="widget-item">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="widget-title">',
        'after_title' => '</h2>',
    ));
}
add_action('widgets_init', 'ourWidgetsInit'); // l2heb vaja et widgetit kasutada


/*
     * Switch default core markup for search form, comment form, and comments  // COMMENTS
     * to output valid HTML5.
*/
    add_theme_support( 'html5', array(
        'search-form',
        'comment-form',
        'comment-list',
        'gallery',
        'caption',
    ) );


if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {  
        wp_enqueue_script( 'comment-reply' );
}

1 个答案:

答案 0 :(得分:1)

在CONTENT.PHP中添加条件

<?php if(is_page()){} else { ?>    
     <a href="<?php the_permalink(); ?>">Read more&raquo;</a>
<?php } ?>

祝你好运