0

我刚刚为 wordpress magento 安装了 Fishpig 扩展。我已经安装了流行的帖子插件。但小部件不会显示在博客侧边栏中。

4

3 回答 3

3

我知道这不是正确的方法,但您可以按照以下步骤获得功能:

导航到您的主题文件夹打开文件posts.phtml

应用程序/设计/前端/您的包/您的主题/模板/wordpress/侧边栏/小部件

并在之前添加以下代码

<?php endif; ?>

编码:

<div class="block block-blog block-recent-posts">
    <?php $resource = Mage::getSingleton('core/resource');
              $readConnection = $resource->getConnection('core_read');
              $query = "SELECT `id`, `post_title`,`post_name` , `comment_count` FROM `wp_posts` WHERE `post_type`='post' ORDER BY `comment_count` DESC LIMIT 10";
              $results = $readConnection->fetchAll($query);
    ?>
    <div class="block-title">
        <?php echo $this->__('Popular Post');  ?>
    </div>
    <div class="block-content">
        <ul>
            <?php foreach($results as $row):?>
            <?php if($row['post_title']!='Auto Draft'):?>
            <li class="item">
            <a href="<?php echo $this->getUrl('blog/').$row['post_name'];?>"> <?php echo $row['post_title'];?></a>
            </li>
            <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </div>
</div>
于 2015-11-23T05:55:18.790 回答
1

请确保您已经为您的 Magento 商店安装了 Fishpig 扩展,并且您还希望在您的站点周围的侧边栏博客(左侧或右侧)中显示热门或最新/最近的帖子(如果您愿意,还可以带有标题和图像/缩略图)。

为此,您需要导航到位置:/app/design/frontend/your-package/default/template/wordpress/打开文件sidebar.phtml

然后将以下代码添加到<div class="wp-sidebar">

    <?php // get post data - OIW
$posts = Mage::getResourceModel('wordpress/post_collection') ->addPostTypeFilter('post')
            ->setOrderByPostDate()
            ->addIsViewableFilter()
            ->setPageSize(10)
            ->load(); ?>
        <?php if (count($posts) > 0): ?>

    <div class="block block-list block-articles">

    <div class="block-title">
                <strong><span><?php echo $this->__('Latest posts') ?></span></strong>
            </div>


    <div class="block-content">

    <ol id="articles-items">
                    <?php foreach($posts as $post): ?>

    <li class="item">
                            <a href="<?php echo $post->getPermalink() ?>"><?php echo $this->escapeHtml($post->getPostTitle()) ?></a>
                        </li>

                    <?php endforeach; ?>
                </ol>

            </div>

        </div>

        <?php endif; ?>
于 2018-04-12T08:35:27.783 回答
0

作为Sushant 响应的补充,如果您使用wordpress-popular-posts插件和Magento Fishpig模块,您可以按如下方式运行任何查询(Magento 1.x):

$readConnection = Mage::helper('wordpress/database')->getReadAdapter();
$query = "select postid, sum(pageviews), p.*
     from wp_popularpostssummary as wp
    LEFT JOIN wp_posts p ON p.ID = wp.postid
    where `view_date` >= date(date_add(now(), INTERVAL -7 day))
    group by postid
    order by sum(pageviews) DESC
    limit 3
    ";
$results = $readConnection->fetchAll($query);

这将运行上述查询,使用 Fishpig_Wordpress 的模块读取连接检索过去 7 天内最热门的帖子。

请注意,最好的方法始终是扩展 Fishpig 模块,将新资源添加到未映射到那里的链接表,并使用Magento ORM查询

于 2020-03-26T04:30:59.030 回答