将“目录”页面中的图像链接到帖子

时间:2017-03-17 作者:NusaMebel

我有一个网站"catalog" page. 它列出了从所有帖子中抓取的所有特色图片。

不幸的是,此“目录”页面中的图像无法单击。我想知道如何让每张图片都可以点击,并将访问者带到相应的帖子。

这是“目录”页面的代码:

<?php
/*
Template Name: katalog
*/
?>
<?php get_header(); ?>

<div class="wpagen-konten">
  <div class="container">
     <div class="row">
        <div class="col-md-12">
           <div class="boxer"><?php virtarich_breadcrumbs(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();  ?>
<h1><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><button class="btn pull-right" name=print value="Print Katalog" onClick="window.print()">Print Katalog <i class="icon-print"></i></button></h1>
<?php the_content(); ?>

<div style="clear: both"></div>
<div class="row"><?php do_action( \'virtarich_katalog\' ); ?>   </div>
<?php endwhile; ?><?php else : ?>
<div class="post"><h2>Not Found</h2>Sorry, but you are looking for something that isn\'t here.</div>
<?php endif; ?>
           </div>
        <div>
     </div>
  </div>
</div>
<?php get_footer(); ?>
任何帮助都将不胜感激。

非常感谢,

-学生-

更新#1:
@DavidLee和@Ian

非常感谢你的帮助。嗯,我对评论部分的文本格式感到困惑。所以,我把代码粘贴在这里。

我想你的意思是:

function virtarich_katalog_function() {
        global $post;
        $vtr_query = new WP_Query(\'showposts=10000\');
        while ($vtr_query->have_posts()) : $vtr_query->the_post(); ?>

            <div class="col-md-3 ikibro">
            <div class="wpagen-produk">
            <div class="katalog-gambar-center">
            <div class="katalog-gambar"><?php virtarich_thumb_normal() ?></div>
            </div>
            <div class="katalog-title"><?php the_title(); ?></div>
            <div class="katalog-harga">Rp <?php virtarich_harga(); ?><span class="coret"><?php virtarich_harga_coret(); ?></span></div>
            <?php if(get_post_meta($post->ID, "kode", $single = true) != ""){ ?> 
                Kode : <?php echo get_post_meta($post->ID, "kode", $single = true);
                 } ?>
                 <br/>

            <?php if(get_post_meta($post->ID, "habis", $single = true)){ ?>
                <div class="habis senter">habis</div>
            <?php } else if(get_post_meta($post->ID, "stok", $single = true) != ""){  ?>
                Stok : <?php echo get_post_meta($post->ID, "stok", $single = true);?>
            <?php } ?>

            </div>
        </div>
如果我没说错的话,我想这就是我的行为准则do_action( \'virtarich_katalog\' );

请CMIIW,

更新#2functions.php 文件

<?php
define(\'VTR_TEMPLATE_DIR_URI\', get_template_directory_uri());
define(\'VTR_TEMPLATE_DIR\', get_template_directory());
define(\'OPTIONS_FRAMEWORK_DIRECTORY\', get_template_directory_uri() . \'/includes/admin/\' );
require ( VTR_TEMPLATE_DIR . \'/includes/admin/options-framework.php\' );
require ( VTR_TEMPLATE_DIR . \'/includes/core/core-function.php\' );
require ( VTR_TEMPLATE_DIR . \'/includes/stores/vtr-store.php\' );
require ( VTR_TEMPLATE_DIR . \'/includes/vtr-style.php\' );

//Filter Halaman Search
function vtr_search_filter($query) {
    if ($query->is_search) {
        $query->set(\'post_type\',array(\'post\'));
    }
return $query;
}
add_filter(\'pre_get_posts\',\'vtr_search_filter\');

//Css Revoslider
function revocss() {?>
<?php if ( is_home() ) { ?>
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/settings.css" media="screen" />
<?php } 
 } add_action(\'wp_footer\', \'revocss\');?>
<?php
非常感谢。

1 个回复
最合适的回答,由SO网友:David Lee 整理而成

在您的功能中virtarich_katalog_function<a> 链接标记如下:

function virtarich_katalog_function() {
        global $post;
        $vtr_query = new WP_Query(\'showposts=10000\');
        while ($vtr_query->have_posts()) : $vtr_query->the_post(); ?>

            <div class="col-md-3 ikibro">
            <div class="wpagen-produk">
            <div class="katalog-gambar-center">
                <div class="katalog-gambar"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php virtarich_thumb_normal() ?></a></div>
            </div>
            <div class="katalog-title"><?php the_title(); ?></div>
            <div class="katalog-harga">Rp <?php virtarich_harga(); ?><span class="coret"><?php virtarich_harga_coret(); ?></span></div>
            <?php if(get_post_meta($post->ID, "kode", $single = true) != ""){ ?> 
                Kode : <?php echo get_post_meta($post->ID, "kode", $single = true);
                 } ?>
                 <br/>

            <?php if(get_post_meta($post->ID, "habis", $single = true)){ ?>
                <div class="habis senter">habis</div>
            <?php } else if(get_post_meta($post->ID, "stok", $single = true) != ""){  ?>
                Stok : <?php echo get_post_meta($post->ID, "stok", $single = true);?>
            <?php } ?>

            </div>
        </div>
更清楚的是,这是一条线:

<div class="katalog-gambar"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php virtarich_thumb_normal() ?></a></div>

相关推荐

Even/Odd every two posts

我需要每两篇文章显示一个不同的布局,是否可以使用偶数/奇数来实现这一点?<?php while (have_posts()): the_post() ?> <?php if ($wp_query->current_post % 2 == 0): ?> even <?php else: ?> odd <?php endif ?> <?php endwhile