Ask your WordPress questions! Pay money and get answers fast! (more info)

Display a list via "wp_list_categories" on a specific page WordPress

  • SOLVED

Hello,

I manage to display a list of categories via "wp_list_categories", and I would like this list to ne display on a specific page.

Someone has an idea how to achieve this ?
Please see the screenshot attach.
Thanks


The page where the list can be seen :
[[LINK href="http://www.headlinesphotos.com/press/"]]http://www.headlinesphotos.com/press/[[/LINK]]

The code used in the above page to display the list :

<div class="about"><ul>
<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />
<li>Agenda Culturel Londres - Galeries</li><br />
<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>
</ul></div>


And here the page where the list should be display (at the left of the thumbnails) :
[[LINK href="http://www.headlinesphotos.com/category/agenda_culturel_londres/"]]http://www.headlinesphotos.com/category/agenda_culturel_londres/[[/LINK]]

Answers (3)

2014-02-07

Sébastien | French WordpressDesigner answers:

only in this page ? that's it ?

use a conditionnal tag like
if (is_page('slug de la page')) { ?>
<div class="about"><ul>

<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />

<li>Agenda Culturel Londres - Galeries</li><br />

<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>

</ul></div>

<?php } ?>


Sébastien | French WordpressDesigner comments:

If it's a category page like http://www.headlinesphotos.com/category/agenda_culturel_londres/
use this code
if(is_category('agenda_culturel_londres') { ?>
<div class="about"><ul>
<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />
<li>Agenda Culturel Londres - Galeries</li><br />
<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>
</ul></div>
<?php } ?>


Sébastien | French WordpressDesigner comments:

and you can paste this code in your file sidebar.php for example, to display this item at the left of your page


Sébastien | French WordpressDesigner comments:

teel me if you have a problem.
And send me your ftp access if you want, and I do that for you
[email protected]


guillaume guillaume comments:

I don't have any sidebar in this theme (imbalance2).
Should I put your code inside "category.php" ?


Sébastien | French WordpressDesigner comments:

absolutely
(are your french ?)


guillaume guillaume comments:

Salut Sebastien,

Voici le code de la page "category.php".
j'ai essayé de coller ton code mais ça a fait bugger le site. Pourrais tu me dire où mettre tes lignes de codes ?

Merci,
Guillaume


<?php get_header(); ?>

<div id="container">
<div id="content" role="main">

<h1 class="page-title"><?php
printf( __( '%s', 'imbalance2' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';

get_template_part( 'loop', 'category' );
?>




</div><!-- #content -->
</div><!-- #container -->

<?php get_footer(); ?>


Sébastien | French WordpressDesigner comments:

ça pourrait être quelque chose comme ça par-exemple :

<?php get_header(); ?>



<div id="container">

<div id="content" role="main">



<h1 class="page-title"><?php

printf( __( '%s', 'imbalance2' ), '<span>' . single_cat_title( '', false ) . '</span>' );

?></h1>

<?php

$category_description = category_description();

if ( ! empty( $category_description ) )

echo '<div class="archive-meta">' . $category_description . '</div>';



get_template_part( 'loop', 'category' );

?>

</div><!-- #content -->


<?php if(is_category('agenda_culturel_londres') { ?>

<div class="about"><ul>

<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />
<li>Agenda Culturel Londres - Galeries</li><br />
<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>
</ul>

</div>

<?php } ?>


</div><!-- #container -->



<?php get_footer(); ?>


guillaume guillaume comments:

J'ai une erreur à la ligne 67.


Sébastien | French WordpressDesigner comments:

toutefois, attention : ceci va afficher tes listes, mais la structure HTML ne sera pas forcément la bonne et le résultat, en terme d'affichage ne sera pas forcement celui que tu veux. Dans ce cas il faudra changer un peu le HTML et la CSS.
Si tu veux je pourrai t'y aider, mais il faudrait que tu m'envoies le fichier de ton thème, ce sera beaucoup plus simple.


Sébastien | French WordpressDesigner comments:

j'ai regardé la demo de imbalance2 et a priori ce thème n'a pas de sidebar, donc il faudra la rajouter.
Envoie-moi ton thème si tu veux. Je regarderai.


guillaume guillaume comments:

Regardes tes mails.
Merci

2014-02-07

Arnav Joy answers:

you can use is_page condition as follows:--



<?php if( is_page( 111 ) ) { ?>

<div class="about"><ul>

<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />

<li>Agenda Culturel Londres - Galeries</li><br />

<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>

</ul></div>

<?php } ?>



where 111 is the id the page where list has to be displayed

2014-02-07

Ryan S answers:

Since we have different idea, I'd like to share mine too, create new sidebar and in category.php or archive.php file just call the new created sidebar

e.g. sidebar file
sidebar-category.php

<div class="about">
<ul>
<?php wp_list_categories('title_li=&include=33,37,36,48,57,58'); ?><br /><br />
<li>Agenda Culturel Londres - Galeries</li><br />
<?php wp_list_categories('title_li=&order=ASC&include=75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60'); ?>
</ul>
</div>


and in your category or archive page, just simply call the new sidebar like so

if(is_category('category-slug')) // where category-slug is the category slug or the category/page you'd like the menu to appear, or you can use category ID too.
get_sidebar('category');



Updated:
I've visited your site and you're using category and yes above is the best solution.

Hope that helps


guillaume guillaume comments:

Hello,

I create the "sidebar-category.php" page then I updated the "category.php" has follow, but it won't work :

<?php get_header(); ?>

<div id="container">
<div id="content" role="main">

<h1 class="page-title"><?php
printf( __( '%s', 'imbalance2' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';

get_template_part( 'loop', 'category' );
?>

if(is_category('agenda_culturel_londres')) // where category-slug is the category slug or the category/page you'd like the menu to appear, or you can use category ID too.

get_sidebar('category');


</div><!-- #content -->
</div><!-- #container -->

<?php get_footer(); ?>


Ryan S comments:

Hi, you should wrap the IF conditional code with PHP tag, or use the ff. code below


<?php get_header(); ?>

<div id="container">
<!--sidebar-->
<aside>
<?php
if(is_category('agenda_culturel_londres')) // where category-slug is the category slug or the category/page you'd like the menu to appear, or you can use category ID too.
get_sidebar('category');
?>
</aside>

<div id="content" role="main">
<h1 class="page-title">
<?php printf( __( '%s', 'imbalance2' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?>
</h1>

<?php
$category_description = category_description();

if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';

get_template_part( 'loop', 'category' );
?>
</div><!-- #content -->
</div><!-- #container -->

<?php get_footer(); ?>